def atoi(a):
    return ord(a) - ord("A")


def itoa(i):
    return chr(i + ord("A"))


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]

    if N == M == 1:
        return S[0]

    same = set(S).intersection(set(T))
    if same:
        return -1

    atob = [-1] * 26
    btoa = [-1] * 26
    for s in S:
        for a, b in zip(s[:-1], s[1:]):
            i = atoi(a)
            j = atoi(b)
            atob[i] = j
            btoa[j] = i
    for t in T:
        for a, b in zip(t[:-1], t[1:]):
            i = atoi(a)
            j = atoi(b)
            if atob[i] == -1:
                atob[i] = j
                btoa[j] = i
            elif atob[i] != j:
                return -1

    now = -1
    for i in range(26):
        if atob[i] != -1 and btoa[i] == -1:
            now = i
            break
    ans = []
    while now != -1:
        ans.append(now)
        now = atob[now]
    res = "".join(itoa(i) for i in ans)
    return res


print(main())