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