while 1:

 n=int(eval(input()))

 if n==0:break

 d={}

 for _ in[0]*n:

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

  d[k]=v

 a=''

 for _ in[0]*int(eval(input())):

  e=input().strip()

  a+=d[e]if e in d else e

 print(a)

import sys

s=sys.stdin

while 1:

 n=int(s.readline())

 if n==0:break

 d={}

 for _ in[0]*n:

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

  d[k]=v

 a=''

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

  e=s.readline().strip()

  a+=d[e]if e in d else e

 print(a)

while 1:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in [0] * n:
        k, v = input().strip().split()
        d[k] = v
    a = ""
    for _ in [0] * int(eval(input())):
        e = input().strip()
        a += d[e] if e in d else e
    print(a)

import sys

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

+import sys + +s = sys.stdin -    n = int(eval(input())) +    n = int(s.readline()) -        k, v = input().strip().split() +        k, v = s.readline().strip().split() -    for _ in [0] * int(eval(input())): -        e = input().strip() +    for _ in [0] * int(s.readline()): +        e = s.readline().strip()