#include using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for(int i=0; ibool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b G[100]; set R[100]; int main(){ int N; cin >> N; int last; vector node(26, -1); REP(i,N){ string A; cin >> A; last = A[0] - 'A'; chmax(node[last], 0); REPi(k,1,A.length()){ int c = A[k] - 'A'; R[c].insert(last); chmax(node[c], 1); G[last].insert(c); last = c; } } int M; cin >> M; REP(i,M){ string A; cin >> A; last = A[0] - 'A'; chmax(node[last], 0); REPi(k,1,A.length()){ int c = A[k] - 'A'; R[c].insert(last); chmax(node[c], 1); G[last].insert(c); last = c; } } vector L; queue S; REP(i,26){ int n = node[i]; if(n == 0){ S.push(i); } } if(S.size() != 1){ cout << -1 << endl; return 0; } while(!S.empty()){ int n = S.front(); S.pop(); L.push_back(n); for(auto&& next : G[n]){ if(R[next].find(n) == R[next].end()){ cout << -1 << endl; return 0; } R[next].erase(n); if(R[next].size() == 0) S.push(next); } } REP(i,L.size()){ printf("%c", L[i]+'A'); } printf("\n"); return 0; }