#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int c = 0; vector T(26, -1); vector S; int N; cin >> N; for (int i = 0; i < N; i++) { string s; cin >> s; S.emplace_back(s); for (const auto& e : s) { if (T[e - 'A'] == -1) T[e - 'A'] = c++; } } int M; cin >> M; for (int i = 0; i < M; i++) { string s; cin >> s; S.emplace_back(s); for (const auto& e : s) { if (T[e - 'A'] == -1) T[e - 'A'] = c++; } } vector> G(c); for (const auto& s : S) { for (int i = 0; i < (int)s.size() - 1; i++) { G[T[s[i] - 'A']].emplace_back(T[s[i + 1] - 'A']); } } auto topological_sort = [&]() { vector in(c, 0); for (int i = 0; i < c; i++) { for (const int j : G[i]) { in[j]++; } } queue que; vector res; for (int i = 0; i < c; i++) { if (in[i] == 0) { que.push(i); res.emplace_back(i); break; } } while (!que.empty()) { const auto u = que.front(); que.pop(); for (const int v : G[u]) { if (--in[v] == 0) { que.push(v); res.emplace_back(v); } } } return res; }; const auto res = topological_sort(); if ((int)res.size() == c) { string s = ""; for (int r : res) { for (int i = 0; i < 26; i++) { if (r == T[i]) s += i + 'A'; } } cout << s << '\n'; } else { cout << -1 << '\n'; } return 0; }