#include #include using ll = long long; const int MOD = 1000000007; const int Mod = 998244353; const int MAX = 1000000005; const long long INF = 1000000000000000005LL; using namespace std; using namespace atcoder; string dfs(int v, int p, vector>& G) { string ret; for (int& nv : G[v]) { if (nv == p) continue; string response = move(dfs(nv, v, G)); for (int i = 0; i < 3; i++) response.pop_back(); ret += "("; ret += response; ret += "yl)"; } ret += "methane"; return ret; } int main() { ios::sync_with_stdio(0); cin.tie(); int N; cin >> N; vector> G(N); dsu d(N); for (int i = 0; i < N; i++) { vector L(4); for (int j = 0; j < 4; j++) cin >> L[j]; for (int j = 0; j < 4; j++) { if (L[j] != "H") { int v = stoi(L[j]) - 1; if (d.same(i, v)) continue; d.merge(i, v); G[i].push_back(v); G[v].push_back(i); } } } cout << dfs(0, -1, G) << endl; }