#include "bits/stdc++.h" #define REP(i,n,N) for(ll i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const ll inf=1e18; const ll NODE_SIZE = 60; int N, M; map mp; int main(){ cin>>N; vector start; int size=0; REP(i,0,N){ string s; cin>>s; size+=s.size(); start.push_back(s[0]); REP(j,0,s.size()-1){ mp[s[j]] = s[j+1]; } } cin>>M; REP(i,0,M){ string s; cin>>s; start.push_back(s[0]); REP(j,0,s.size()-1){ mp[s[j]] = s[j+1]; } } sort(ALL(start)); start.erase(unique(ALL(start)), start.end()); for(auto c:start){ string s; char now = c; s += now; while(mp.find(now) != mp.end()){ now = mp[now]; s += now; } if(s.size()==size){ p(s); return 0; } } p(-1); return 0; }