Create a program to convert data based on a given conversion table. The characters used in the data are alphanumeric, with case sensitivity. The conversion table consists of pairs of characters separated by a space. When a character from the table appears in the data, it is converted to the second character in the pair. If a character does not appear in the table, it remains unchanged. The input file contains the conversion table (first n + 1 lines) followed by the data to be converted (starting from line n + 2). The output should be a single line without any intermediate spaces or line breaks. The input consists of multiple datasets, ending when n equals 0. The number of datasets does not exceed 5. For each dataset, output the converted string on a separate line.

# Buggy version:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    dic = {}
    n = int(input())
    if n == 0:
        break

    for i in range(n):
        key, value = input().split()
        dic[key] = value
    print(dic)
    ret = ''

    m = int(input())
    for i in range(m):
        s = input().split()[0]
        ret += dic.get(s, s)

    print(ret)

# Fixed version:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    dic = {}
    n = int(input())
    if n == 0:
        break

    for i in range(n):
        key, value = input().split()
        dic[key] = value

    ret = ''

    m = int(input())
    for i in range(m):
        s = input().strip()
        ret += dic.get(s, s)

    print(ret)

# Buggy version:
while True:
    x = int(input())
    if x == 0:
        break
    dcl = dict()
    for i in range(x):
        inp = list(map(str, input().split()))
        dcl[inp[0]] = inp[1]
    ans = ""
    x = int(input())
    for i in range(x):
        y = str(input())
        if y in dcl:
            ans += dcl[y]
        else:
            ans += y
    print(ans)
    print()

# Fixed version:
while True:
    x = int(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(input())
    for i in range(x):
        y = str(input()[0])
        if y in dcl:
            ans += dcl[y]
        else:
            ans += y
    print(ans)

# Buggy version:
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = map(str, input().split())
        pre += l[0]
        post += l[1]
    m = int(input())
    data = ""
    for _ in range(m):
        data += input()
    print(data.translate(str.maketrans(pre, post)))

# Fixed version:
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = input().strip().split()
        pre += l[0]
        post += l[1]
    m = int(input())
    data = ""
    for _ in range(m):
        data += input().strip()
    print(data.translate(str.maketrans(pre, post)))

# Buggy version:
import sys

while True:
    n = int(input())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    y = []
    for i in range(int(input()):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

# Fixed version:
import sys

while True:
    n = int(input())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = input().split()
        x[k] = v
    y = []
    for i in range(int(input())):
        a = input()[0]
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

# Buggy version:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    tmp = [input().strip() for _ in range(int(input()))]
    ans = [d[a] if a in d.keys() else a for a in tmp]
    print("".join(ans))

# Fixed version:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    tmp = [input().strip() for _ in range(int(input()))]
    ans = [d[a] if a in d.keys() else a for a in tmp]
    print("".join(ans))

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


# Fixed version:
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()

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


# Fixed version:
import sys
r=lambda:sys.stdin.readline().strip()
while 1:
 n=int(r())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=r().split()
  d[k]=v
 a=''
 for _ in[0]*int(r()):
  e=r()
  a+=d[e]if e in d else e
 print(a)

# Buggy version:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  k,v=s()[:-1].split()
  d[k]=v
 print(d.get(*[s()[0]]*2)for _ in[0]*int(s()),sep='')


# Fixed version:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  k,v=s()[:-1].split()
  d[k]=v
 print(*[d.get(*[s()[0]]*2)for _ in[0]*int(s())],sep='')

# Buggy version:
# AOJ 0501: Data Conversion
# Python3 2018.6.29 bal4u

while True:
	n = int(input())
	if n == 0: break
	tbl = {}
	for i in range(n):
		a, b = input().split()
		print("i=",i,a,b)
		tbl[a] = b
	ans = ''
	m = int(input())
	for i in range(m):
		a = input()[0]
		if a in tbl: ans += tbl[a]
		else: ans += a
	print(ans)


# Fixed version:
# AOJ 0501: Data Conversion
# Python3 2018.6.29 bal4u

while True:
	n = int(input())
	if n == 0: break
	tbl = {}
	for i in range(n):
		a, b = input().split()
		tbl[a] = b
	ans = ''
	m = int(input())
	for i in range(m):
		a = input()[0]
		ans += tbl[a] if a in tbl else a
	print(ans)