#include #define rep(i, a, n) for(int i = a; i < n; i++) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define fi first #define se second using namespace std; typedef pair P; signed main(){ int n; cin >> n; int G[26][26] = {}; int cnt = 0; string s; rep(i, 0, n){ cin >> s; cnt += s.size(); rep(j, 0, s.size() - 1){ G[s[j] - 'A'][s[j + 1] - 'A'] = 1; // G[s[j + 1] - 'a']. push_back(s[j] - 'a'); } } int m; cin >> m; rep(i, 0, m){ cin >> s; rep(j, 0, s.size() - 1){ G[s[j] - 'A'][s[j + 1] - 'A'] = 1; // G[s[j + 1] - 'a']. push_back(s[j] - 'a'); } } if(cnt == 1){ cout << s << endl; return 0; } int st = -1; bool f = true; rep(i, 0, 26){ int tmp = 0; rep(j, 0, 26){ if(G[i][j]){ tmp++; } } if(tmp > 1) f = false; int tmp2 = 0; rep(j, 0, 26){ if(G[j][i]){ tmp2++; } } if(tmp2 > 1) f = false; if(tmp == 1 && tmp2 == 0){ if(st == -1) st = i; else f = false; } } if(st == -1) f = false; // cout << f << endl; // cout << " "; // rep(i, 0, 26){ // cout << (char)('A' + i) << " "; // } // cout << endl; // rep(i, 0 ,26){ // cout << (char)('A' + i) << " "; // rep(j, 0, 26){ // cout << G[i][j] << " "; // } // cout << endl; // } string ans = ""; int now = st; ans += (char)('A' + st); // cout << ans << endl; while(1){ bool upd = false; rep(i, 0, 26){ if(G[now][i]){ upd = true; now = i; ans += ('A' + now); } } if(!upd) break; } if(ans.size() != cnt) f = false; if(!f) cout << -1 << endl; else cout << ans << endl; }