N = int(input()) A = [input() for _ in range(N)] M = int(input()) B = [input() for _ in range(M)] G = {s: set() for a in A for s in a} first_dict = {s: True for s in G.keys()} for a in A: for i in range(len(a) - 1): G[a[i]].add(a[i + 1]) first_dict[a[i + 1]] = False for b in B: for i in range(len(b) - 1): G[b[i]].add(b[i + 1]) first_dict[b[i + 1]] = False def is_impossible(b): if b: print(-1) exit() first = [k for k, v in first_dict.items() if v] is_impossible(len(first) != 1) cur = first[0] ans = cur for _ in range(len(G) - 1): is_impossible(len(G[cur]) != 1) cur = G[cur].pop() ans += cur print(ans)