import sys while True: try: ss = input().strip().split() n = int(ss[0]) L = [] L.append(ss[1]) c_list = ss[2:-1] #按规则构造列表 for i in range(n-1): v = c_list[2*i] f = c_list[2*i + 1] # print(v,f) index = L.index(f) # print(index) L.insert(index + 1, v) # print(L) L.remove(ss[-1]) # if len(L) == 0: # print("0") # else: print(" ".join(L)) except: # print(sys.exc_info()) break