N = int(input()) A = [input() for _ in range(N)] M = int(input()) B = [input() for _ in range(M)] for i in range(N): for j in range(M): if A[i][0] == B[j][0]: str0, str1 = A.pop(i), B.pop(j) break else: continue break while True: if str0 == str1: if len(A) == 0 and len(B) == 0: print(str0) else: print(-1) break if len(str0) > len(str1): for i in range(len(B)): if B[i][0] == str0[len(str1)]: str1 += B.pop(i) break else: for i in range(len(A)): if A[i][0] == str1[len(str0)]: str0 += A.pop(i) break