N = int(input()) D = {} for _ in range(N): a, b = map(str, input().split()) D[a] = b while b in D: b = D[b] D[a] = b ans = [] for b in D.values(): if not b in ans: ans.append(b) for b in ans: print(b)