#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(const vector>& Alkane, int root, vector& visited){ visited[root] = true; string name = ""; for (int child : Alkane[root]){ if (visited[child]) continue; string ChildName = GetName(Alkane, child, visited); 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'); } } } vector visited(N, false); cout << GetName(Alkane, 0, visited) << endl; return 0; }