import java.io.*; import java.util.*; public class Main_yukicoder517 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); char[][] a = new char[n][]; for (int i = 0; i < n; i++) { a[i] = sc.next().toCharArray(); } int m = sc.nextInt(); char[][] b = new char[m][]; for (int i = 0; i < m; i++) { b[i] = sc.next().toCharArray(); } int[] next = new int[26]; Arrays.fill(next, -2); for (char[] s : a) { for (int i = 0, size = s.length - 1; i < size; i++) { next[s[i] - 'A'] = s[i + 1] - 'A'; } next[s[s.length - 1] - 'A'] = -1; } for (char[] s : b) { for (int i = 0, size = s.length - 1; i < size; i++) { next[s[i] - 'A'] = s[i + 1] - 'A'; } } Set hs = new HashSet<>(); int cnt = 0; for (int i = 0, size = next.length; i < size; i++) { if (next[i] == -1) { cnt++; } if (next[i] != -2) { hs.add(next[i]); } } if (cnt > 1) { pr.println("-1"); return; } for (int i = 0, size = next.length; i < size; i++) { if (next[i] != -2 && !hs.contains(i)) { StringBuilder ret = new StringBuilder(); int j = i; while (j >= 0) { ret.append((char)(j + 'A')); j = next[j]; } pr.println(ret); break; } } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }