//#define LOCAL #include #include #include #include #include #include #include #include #define int long long //typedef long long ll; #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; int N, M; string in[52]; int len; string ans; void dfs(string str) { if (str.length() > ans.length()) { ans = str; //cout << "ans = " << ans << endl; } char fst = str[0]; char lst = str[str.length()-1]; rep(i, N + M) { if (in[i].find(fst) != string::npos && in[i].find(fst) >= 1) { dfs(in[i].substr(0, in[i].find(fst)) + str); } if (in[i].find(lst) != string::npos && in[i].find(lst) < in[i].length() - 1) { dfs(str + in[i].substr(in[i].find(lst) + 1)); } } } signed main() { #ifdef LOCAL ifstream in("input.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> N; rep(i,N) { cin >> in[i]; len += in[i].length(); } cin >> M; rep(i,M) cin >> in[N+i]; dfs(in[0]); if (ans.length() == len) { cout << ans << endl; } else { cout << -1 << endl; } }