#include using namespace std; #define rep(i,n) for (long long i = 0; i < n; ++i) using ll = long long; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 998244353; constexpr bool debug = false; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } //---------------------------------// string GetName(vector> Alkane, int root){ string name = ""; vector> ChildAlkane = Alkane; ChildAlkane[root].clear(); for (int child : Alkane[root]){ ChildAlkane[child].erase(root); } for (int child : Alkane[root]){ string ChildName = GetName(ChildAlkane, child); for (int cnt = 0; cnt < 3; cnt++) ChildName.pop_back(); name += "(" + ChildName + "yl)"; } name += "methane"; return name; } int main(){ int N; cin >> N; vector> Alkane(N, set()); for (int i = 0; i < N; ++i){ for (int j = 0; j < 4; ++j){ char c; cin >> c; if (c != 'H'){ Alkane[i].insert(c-'1'); } } } cout << GetName(Alkane, 0) << endl; return 0; }