import sys

s=sys.stdin.readline

while 1:

 n=int(s())

 if n==0:break

 d={}

 for _ in[0]*n:

  k,v=s().strip().split()

  d[k]=v

 a=''

 for _ in[0]*int(s()):

  a+=d.get(*[s().strip()]*2)

 print(a)

import sys

s=sys.stdin.readline

while 1:

 n=int(s())

 if n==0:break

 d={}

 for _ in[0]*n:

  k,v=s().strip().split()

  d[k]=v

 print((''.join(d.get(*[s().strip()]*2)for _ in[0]*int(s()))))

import sys

s = sys.stdin.readline
while 1:
    n = int(s())
    if n == 0:
        break
    d = {}
    for _ in [0] * n:
        k, v = s().strip().split()
        d[k] = v
    a = ""
    for _ in [0] * int(s()):
        a += d.get(*[s().strip()] * 2)
    print(a)

import sys

s = sys.stdin.readline
while 1:
    n = int(s())
    if n == 0:
        break
    d = {}
    for _ in [0] * n:
        k, v = s().strip().split()
        d[k] = v
    print(("".join(d.get(*[s().strip()] * 2) for _ in [0] * int(s()))))

-    a = "" -    for _ in [0] * int(s()): -        a += d.get(*[s().strip()] * 2) -    print(a) +    print(("".join(d.get(*[s().strip()] * 2) for _ in [0] * int(s()))))