#include "bits/stdc++.h" #define MOD 1000000007 #define INF 11234567890 #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i> N; rep(i, N) { in >> A[i]; } in >> M; rep(i, M) { in >> B[i]; } ans = A[0]; while (true) { bool ok = false; rep(i, N) { rep(j, A[i].length()) { if (A[i][j] == ans[ans.length() - 1]) { bool flag = true; int cou = 0; rep(k, j) { if (ans[ans.length() - j - 1 + k] != A[i][k]) { flag = false; break; } } if (flag) { ok = true; ans = ans.substr(0, ans.length() - (j + 1)) + A[i]; A[i].erase(); } } if (A[i][j] == ans[0]) { bool flag = true; int cou = 0; for (int k = j; k < std::min(ans.length(), A[i].length()); ++k) { if (ans[k] != A[i][k]) { flag = false; break; } } if (flag) { ok = true; ans = A[i].substr(0, j) + ans; A[i].erase(); } } } rep(j, B[i].length()) { if (B[i][j] == ans[ans.length() - 1]) { bool flag = true; int cou = 0; rep(k, j) { if (ans[ans.length() - j - 1 + k] != B[i][k]) { flag = false; break; } } if (flag) { ok = true; ans = ans.substr(0, ans.length() - (j + 1)) + B[i]; B[i].erase(); } } if (B[i][j] == ans[0]) { bool flag = true; int cou = 0; for (int k = j; k < std::min(ans.length(), B[i].length()); ++k) { if (ans[k] != B[i][k]) { flag = false; break; } } if (flag) { ok = true; ans = B[i].substr(0, j) + ans; B[i].erase(); } } } } if (!ok) { break; } } out << ans << std::endl; return 0; }