Hide

Problem L
Video Games

Alice, Bob, and Charlie share a collection of video game cartridges. This way, only one of them needs to own a game in order for them all to enjoy it. The popular games right now are a fishing game, a golf game, and a hockey game.

Initially, Alice has the fishing game, Bob has the golf game, and Charlie has the hockey game. Over time, the games gets passed around between them and it can be hard to keep track of who currently has each game.

Given a sequence of requests indicating that a particular friend wants to play a particular game, determine who they have to borrow that game from.

Input

The first line of input contains a single integer $N$ ($1 \leq N \leq 100$) indicating the number of requests. Then $N$ lines follow describing the requests, the $i$-th line contains the text $a_i$ wants to play $b_i$ where $a_i$ is one of alice, bob, or charlie and $b_i$ is one of fishing, golf, or hockey.

After the $i$-th request, friend $a_i$ is now in possession of game $b_i$.

Output

For each request $i$, output a single line containing one of the following messages. If $a_i$ was already in possession of game $b_i$ then output the message “$a_i$ already has $b_i$” (without quotes). If $a_i$ was not already in possession of $b_i$ then output the message “$a_i$ borrows $b_i$ from $c_i$” (again without quotes) where $c_i$ is the name of the friend who was in possession of game $b_i$ at this time.

Sample Input 1 Sample Output 1
4
alice wants to play golf
bob wants to play golf
charlie wants to play hockey
charlie wants to play fishing
alice borrows golf from bob
bob borrows golf from alice
charlie already has hockey
charlie borrows fishing from alice

Please log in to submit a solution to this problem

Log in