pl = input().split() time = int(input()) for _ in range(time): rnd = input().split() if pl[0] in rnd: rnd.remove(pl[0]) pl = rnd print(pl[0])