n = int(input())
current = {
  "fishing": "alice",
  "golf": "bob",
  "hockey": "charlie"
}

for _ in range(n):
  person, _, _, _, game = input().split()
  if current[game] != person:
    print(f"{person} borrows {game} from {current[game]}")
  else:
    print(f"{person} already has {game}")
  current[game] = person
