import sys input = sys.stdin.read sys.setrecursionlimit(300000) def dfs(start): stk, p, vis = [(start, -1)], [-1] * (N + 1), [False] * (N + 1) vis[start] = True order = [] while stk: n, par = stk.pop() order.append((n, par)) for nei in adj[n]: if not vis[nei]: vis[nei] = True stk.append((nei, n)) p[nei] = n names = [""] * (N + 1) for n, par in reversed(order): if not adj[n]: names[n] = "methane" else: b = sorted(names[nei][:-3] for nei in adj[n] if nei != par) names[n] = "".join(f"({branch}yl)" for branch in b) + "methane" return names[start] d = input().split() N = int(data[0]) adj = [[] for _ in range(N + 1)] idx = 1 for i in range(1, N + 1): for _ in range(4): n = d[idx] idx += 1 if n != 'H': n = int(n) if n != i: adj[i].append(n) print(dfs(1))