#include using namespace std; int root[26]; int nex[26]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; int m; cin >> m; vector b(m); for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < 26; i++) { root[i] = -1; nex[i] = -1; } for (int i = 0; i < n; i++) { if (root[a[i][0] - 'A'] == -1) root[a[i][0] - 'A'] = 1; for (int j = 0; j + 1 < a[i].length(); j++) { root[a[i][j + 1] - 'A'] = 0; nex[a[i][j] - 'A'] = a[i][j + 1] - 'A'; } } for (int i = 0; i < m; i++) { if (root[b[i][0] - 'A'] == -1) root[b[i][0] - 'A'] = 1; for (int j = 0; j + 1 < b[i].length(); j++) { root[b[i][j + 1] - 'A'] = 0; nex[b[i][j] - 'A'] = b[i][j + 1] - 'A'; } } int idx = -1; for (int i = 0; i < 26; i++) { if (root[i] == 1) { if (idx == -1) idx = i; else { idx = -1; break; } } } if (idx == -1) { cout << -1 << endl; return 0; } for (int i = idx; i != -1; i = nex[i]) { cout << (char)('A' + i); } cout << endl; return 0; }