import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 sys.setrecursionlimit(2 * 10 ** 5 + 1) n = ii() graph = [[] for _ in range(n)] for i in range(n): a, b, c, d = input().split() if a != 'H': a = int(a) - 1 graph[i].append(a) if b != 'H': b = int(b) - 1 graph[i].append(b) if c != 'H': c = int(c) - 1 graph[i].append(c) if d != 'H': d = int(d) - 1 graph[i].append(d) from collections import deque def TreeDepth(s, graph): inf = 2 ** 61 - 1 n = len(graph) depth = [inf] * n depth[s] = 0 q = deque() q.append(s) while q: now = q.popleft() for to in graph[now]: if depth[to] == inf: depth[to] = depth[now] + 1 q.append(to) return depth TD = TreeDepth(0, graph) h = {} cnt = 0 ans = [] def dfs(now): global ans for to in graph[now]: if TD[to] > TD[now]: ans.append('(') dfs(to) ans.append('methyl)') dfs(0) print(''.join(ans) + 'methane')