#include #define rep(i,a,b) for(int i=int(a);i st; cin >> N; rep(i,0,N){ string s; cin >> s; st.insert(s); } cin >> M; rep(i,0,M){ string s; cin >> s; st.insert(s); } bool flag = 1; while(st.size() != 1 && flag){ flag = 0; next: for(auto S = st.begin();S != st.end();S++) for(auto T = st.begin();T != st.end();T++){ //cout << *S << " " << *T << endl; if(S == T)continue; string str = cat(*S,*T); //cout << "str:" << str << endl; if(str != ""){ flag = 1; st.erase(S); st.erase(T); st.insert(str); //cout << "hogeee" << endl; goto next; } } //cout << st.size() << endl; } if(st.size() == 1)cout << *st.begin() << endl; else cout << -1 << endl; }