import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] next = new int[26]; int size = 0; Arrays.fill(next, -1); HashSet starts = new HashSet<>(); for (int i = 0; i < n; i++) { char[] arr = br.readLine().toCharArray(); size += arr.length; for (int j = 0; j < arr.length - 1; j++) { next[arr[j] - 'A'] = arr[j + 1] - 'A'; } starts.add(arr[0] - 'A'); } int m = Integer.parseInt(br.readLine()); for (int i = 0; i < m; i++) { char[] arr = br.readLine().toCharArray(); for (int j = 0; j < arr.length - 1; j++) { next[arr[j] - 'A'] = arr[j + 1] - 'A'; } } for (int x : starts) { StringBuilder sb = new StringBuilder(); sb.append((char)(x + 'A')); while (next[x] != -1) { x = next[x]; sb.append((char)(x + 'A')); } if (sb.length() == size) { System.out.println(sb); return; } } System.out.println(-1); } }