#include<bits/stdc++.h>
using namespace std;
string dfs(int node, vector<vector<int>>& adj){
string res = "";
res.push_back(node+'A');
for(auto it: adj[node]){
res += '(' + dfs(it, adj) +')';
}
return res;
}
int main(){
int n = 8;
vector<vector<char>> v({{'A','B'}, {'A', 'C'}, {'B', 'G'}, {'C', 'H'}, {'E', 'F'}, {'B', 'D'}, {'C', 'E'}});
vector<vector<int>> adj(8);
vector<int> parent(8, -1);
for(auto e: v){
adj[e[0]-'A'].push_back(e[1]-'A');
parent[e[1]-'A'] = e[0]-'A';
}
for(auto &it:adj){
sort(it.begin(), it.end());
}
int root;
for(int i=0;i<n;i++){
if(parent[i]==-1) root = i;
}
cout<<'(' + dfs(root, adj)+')'<<endl;
return 0;
}