import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashSet starts = new HashSet<>(); int[] next = new int[26]; Arrays.fill(next, -1); boolean[] used = new boolean[26]; for (int i = 0; i < n; i++) { char[] arr = sc.next().toCharArray(); starts.add(arr[0] - 'A'); used[arr[0] - 'A'] = true; for (int j = 0; j < arr.length - 1; j++) { next[arr[j] - 'A'] = arr[j + 1] - 'A'; used[arr[j + 1] - 'A'] = true; } } int count = 0; for (boolean b : used) { if (b) { count++; } } int m = sc.nextInt(); for (int i = 0; i < m; i++) { char[] arr = sc.next().toCharArray(); starts.add(arr[0] - 'A'); for (int j = 0; j < arr.length - 1; j++) { if (next[arr[j] - 'A'] >= 0 && next[arr[j] - 'A'] != arr[j + 1] - 'A') { System.out.println(-1); return; } next[arr[j] - 'A'] = arr[j + 1] - 'A'; } } for (int x : starts) { int cur = x; int c = 0; StringBuilder sb = new StringBuilder(); sb.append((char)(cur + 'A')); while (next[cur] >= 0) { cur = next[cur]; sb.append((char)(cur + 'A')); c++; } if (c == count - 1) { System.out.println(sb); return; } } System.out.println(-1); } }