circle = input() for i in range(int(input())): a,b = input().split() if a==circle: circle = b print(circle)