while True:

    x = int(eval(input()))

    if x == 0:

        break

    dcl = {}

    for i in range(x):

        inp = list(map(str, input().split()))

        dcl[inp[0]] = inp[1]

    ans = ""

    x = int(eval(input()))

    for i in range(x):

        y = str(input()[0])

        if y in dcl:

            ans += dcl[y]

        else:

            ans += y

    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 += d.get(a, a)

    print(ans)
while True:
    x = int(eval(input()))
    if x == 0:
        break
    dcl = {}
    for i in range(x):
        inp = list(map(str, input().split()))
        dcl[inp[0]] = inp[1]
    ans = ""
    x = int(eval(input()))
    for i in range(x):
        y = str(input()[0])
        if y in dcl:
            ans += dcl[y]
        else:
            ans += y
    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 += d.get(a, a)
    print(ans)

-    x = int(eval(input())) -    if x == 0: +    n = int(eval(input())) +    if n == 0: -    dcl = {} -    for i in range(x): -        inp = list(map(str, input().split())) -        dcl[inp[0]] = inp[1] +    d = {} +    for _ in range(n): +        a, b = input().split() +        d[a] = b +    m = int(eval(input())) -    x = int(eval(input())) -    for i in range(x): -        y = str(input()[0]) -        if y in dcl: -            ans += dcl[y] -        else: -            ans += y +    for _ in range(m): +        a = input().strip() +        ans += d.get(a, a)