#include using namespace std; #define FOR(i, n) for(int i = 0; i < (n); i++) #define MEM(a, x) memset(a, x, sizeof(a)) #define ALL(a) a.begin(), a.end() #define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) typedef long long ll; typedef pair P; int n, m; char nex[30]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin >> n; fill(nex, nex+30, 'z'); bool ok = true; int cnt = 0; FOR(i, n) { string s; cin >> s; cnt += s.size(); FOR(j, s.size()-1) { if (nex[s[j]-'A'] == 'z') nex[s[j]-'A'] = s[j+1]; else if (nex[s[j]-'A'] != s[j+1]) ok = false; } } cin >> m; FOR(i, m) { string s; cin >> s; FOR(j, s.size()-1) { if (nex[s[j]-'A'] == 'z') nex[s[j]-'A'] = s[j+1]; else if (nex[s[j]-'A'] != s[j+1]) ok = false; } } int cnt2 = 0; FOR(i, 26) { if (nex[i] != 'z') cnt2++; } if (!ok || cnt != cnt2+1) { cout << -1 << endl; return 0; } FOR(i, 26) { string ret = ""; for (char c = (char)('A'+i); c != 'z'; c = nex[c-'A']) { ret += string(1, c); } if (ret.size() == cnt) { cout << ret << endl; return 0; } } return 0; }