while True:

    n = int(eval(input()))

    if n == 0:

        break

    d = {}

    for _ in range(n):

        a, b = input().split()

        d[a] = b

    m = int(eval(input()))

    ans = []

    for _ in range(m):

        a = input().strip()

        if a in list(d.keys()):

            ans.append(d[a])

        else:

            ans.append(a)

    print(("".join(ans)))
while True:

    n = int(eval(input()))

    if n == 0:

        break

    d = {}

    for _ in range(n):

        a, b = input().split()

        d[a] = b

    tmp = [input().strip() for _ in range(int(eval(input())))]

    ans = [d[a] if a in list(d.keys()) else a for a in tmp]

    print(("".join(ans)))
while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(eval(input()))
    ans = []
    for _ in range(m):
        a = input().strip()
        if a in list(d.keys()):
            ans.append(d[a])
        else:
            ans.append(a)
    print(("".join(ans)))

while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    tmp = [input().strip() for _ in range(int(eval(input())))]
    ans = [d[a] if a in list(d.keys()) else a for a in tmp]
    print(("".join(ans)))

-    m = int(eval(input())) -    ans = [] -    for _ in range(m): -        a = input().strip() -        if a in list(d.keys()): -            ans.append(d[a]) -        else: -            ans.append(a) +    tmp = [input().strip() for _ in range(int(eval(input())))] +    ans = [d[a] if a in list(d.keys()) else a for a in tmp]