#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); set used; bool head[128]; char nxt[128]; string solve() { int h = 0; char x; for (char c = 'A'; c <= 'Z'; c++) { if (used.count(c) && head[c]) { x = c; ++h; } } if (h != 1) return ""; string ret; while (x) { ret += x; x = nxt[x]; } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); fill(head, head + 128, true); REP (i, 2) { int n; cin >> n; REP (j, n) { string s; cin >> s; for (int k = 0; k < s.length(); k++) { used.insert(s[k]); if (k > 0) head[s[k]] = false; if (k + 1 < s.length()) nxt[s[k]] = s[k+1]; } } } string ret = solve(); cout << (ret.empty() ? "-1" : ret) << endl; return 0; }