while True:

	dict = {}

	n = eval(input())

	if n == 0:break

	for x in range(n):

		a, b = input().split()

		dict[a.strip()] = b.strip()

	res = ""

	for x in range(eval(input())):

		a = input().strip()

		if a in dict:

			res += dict[a]

		else:

			res += a

	print(res)
while True:

	dict = {}

	n = eval(input())

	if n == 0:break

	for x in range(n):

		a, b = input().split()

		dict[a] = b

	res = ""

	for x in range(eval(input())):

		a = input()[0]

		if a in dict:

			res += dict[a]

		else:

			res += a

	print(res)
while True:
    dict = {}
    n = eval(input())
    if n == 0:
        break
    for x in range(n):
        a, b = input().split()
        dict[a.strip()] = b.strip()
    res = ""
    for x in range(eval(input())):
        a = input().strip()
        if a in dict:
            res += dict[a]
        else:
            res += a
    print(res)

while True:
    dict = {}
    n = eval(input())
    if n == 0:
        break
    for x in range(n):
        a, b = input().split()
        dict[a] = b
    res = ""
    for x in range(eval(input())):
        a = input()[0]
        if a in dict:
            res += dict[a]
        else:
            res += a
    print(res)

-        dict[a.strip()] = b.strip() +        dict[a] = b -        a = input().strip() +        a = input()[0]