from sys import stdin
from collections import defaultdict
n = int(stdin.readline())
tree = defaultdict(list)
for _ in range(n):
root, l, r = stdin.readline().strip().split()
tree[root] = [l, r]
print(tree)
result = [""] * 3 #전위, 중위, 후위
def traverse(node):
result[0] += node
if tree[node][0] != ".":
traverse(tree[node][0]) #왼쪽
result[1] += node
if tree[node][1] != ".":
traverse(tree[node][1]) #오른쪽
result[2] += node
traverse("A")
for i in result:
print(i)