while 1:

 n=int(input())

 if n==0:break

 d={}

 for _ in[0]*n:

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

  d[k]=v

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

  e=input().strip()

  print(d[e]if e in d else e,end='')

 print()

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)

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

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)

-    n = int(input()) +    n = int(eval(input())) -    for _ in [0] * int(input()): +    a = "" +    for _ in [0] * int(eval(input())): -        print(d[e] if e in d else e, end="") -    print() +        a += d[e] if e in d else e +    print(a)