#include using namespace std; using ll = long long; struct Act { int type; // 0: node, 1: char, 2: suffix int u, p; bool is_root; char ch; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> C(n); for (int i = 0; i < n; i++) { for (int k = 0; k < 4; k++) { string s; cin >> s; if (s == "H") C[i][k] = -1; else C[i][k] = (int)stoll(s) - 1; // stoll 推奨 } } vector st; st.push_back({0, 0, -1, true, 0}); // root を 0(=炭素1)に決める while (!st.empty()) { Act a = st.back(); st.pop_back(); if (a.type == 1) { cout << a.ch; continue; } if (a.type == 2) { cout << (a.is_root ? "methane" : "methyl"); continue; } // node a.u を展開: // ( child )( child ) ... + suffix を出す st.push_back({2, a.u, a.p, a.is_root, 0}); // 最後に語尾 // LIFO なので、子を逆順に積む(順番は自由なのでどれでもOK) for (int k = 3; k >= 0; k--) { int v = C[a.u][k]; if (v < 0 || v == a.p) continue; st.push_back({1, 0, 0, false, ')'}); st.push_back({0, v, a.u, false, 0}); st.push_back({1, 0, 0, false, '('}); } } cout << '\n'; }