import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) a = [input() for _ in range(n)] m = int(input()) b = [input() for _ in range(m)] ns = [[] for _ in range(26)] rns = [[] for _ in range(26)] ds = [0]*26 seen = [0]*26 for s in a+b: for i in range(len(s)): ci = ord(s[i]) - ord("A") seen[ci] = 1 for j in range(i): cj = ord(s[j]) - ord("A") ns[cj].append(ci) rns[ci].append(cj) ds[cj] += 1 seen[ci] = seen[cj] = 1 def cycle(rns, ds): """出次数0の頂点を削除しつづける DAGならTPS順序も求まる rns: 逆辺の隣接リスト ds: もとのグラフにおける出次数 返り値 vs: 除かれた頂点 done: 除いたフラグ """ from collections import deque q = deque() n = len(rns) done = [False] * n ok = 1 for u in range(n): if ds[u]==0: if not seen[u]: done[u] = True continue q.append(u) done[u] = True vs = [] while q: # print([chr(ord("A")+v) for v in q]) if len(q)>=2: ok = 0 u = q.popleft() vs.append(u) for v in rns[u]: if done[v]: continue ds[v] -= 1 if ds[v]==0: done[v] = True q.append(v) return vs,done,ok vs,done,ok = cycle(rns,ds) if all(done): if ok: ans = "".join(map(chr, ((ord("A")+v) for v in vs)))[::-1] else: ans = -1 else: ans = -1 print(ans)