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()

        ans += d.get(a, a)

    print(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()

        ans.append(d.get(a, 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
    m = int(eval(input()))
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d.get(a, a)
    print(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()
        ans.append(d.get(a, a))
    print(("".join(ans)))

-    ans = "" +    ans = [] -        ans += d.get(a, a) -    print(ans) +        ans.append(d.get(a, a)) +    print(("".join(ans)))