import sys input = sys.stdin.readline sys.setrecursionlimit(200020) N=int(input()) C=[input().split() for i in range(N)] USE=[0]*N from functools import lru_cache @lru_cache(maxsize=None) def dfs(x): USE[x]=1 ANS=[] for i in range(4): if C[x][i]=="H": continue k=int(C[x][i])-1 if USE[k]==1: continue ANS.append("(") ANS.append("".join(dfs(k))) ANS.append(")") ANS.append("methyl") #print(ANS) return ANS ANS=dfs(0) ANS[-1]="methane" print("".join(ANS))