Problem:


与えられた変換表にもとづき，データを変換するプログラムを作成しなさい．

データに使われている文字は英字か数字で，英字は大文字と小文字を区別する．変換表に現れる文字の順序に規則性はない．

変換表は空白をはさんで前と後ろの 2 つの文字がある(文字列ではない)．変換方法は，変換表のある行の前の文字がデータに現れたら，そのたびにその文字を後ろの文字に変換し出力する．変換は 1 度だけで，変換した文字がまた変換対象の文字になっても変換しない．変換表に現れない文字は変換せず，そのまま出力する．

入力ファイルには，変換表（最初の n + 1 行）に続き変換するデータ（n + 2 行目以降）が書いてある． 1 行目に変換表の行数 n，続く n 行の各行は，空白をはさんで 2 つの文字，さらに続けて， n + 2 行目に変換するデータの行数 m，続く m 行の各行は 1 文字である． m ≤ 105 とする．出力は，出力例のように途中に空白や改行は入れず 1 行とせよ．

 

  入力例
 

3

A a

0 5

5 4

10

A

B

C

0

1

4

5

a

b

A

  　

  出力例

aBC5144aba

入力

入力は複数のデータセットからなる．n が 0 のとき入力が終了する．データセットの数は 5 を超えない．

出力

データセットごとに、変換後の文字列を１行に出力する．

入力例

3	
A a	
0 5	
5 4	
10	
A	
B	
C	
0	
1	
4	
5	
a	
b	
A
3	
A a	
0 5	
5 4	
10	
A	
B	
C	
0	
1	
4	
5	
a	
b	
A
0

出力例

aBC5144aba
aBC5144aba

各データセットの出力（変換後の文字列）の後に改行を入れること．

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0


Sample output:
aBC5144aba
aBC5144aba

Submission status: Runtime Error

Solution code:
out = []
while True:
  n = int(raw_input())
  if n == 0: break
  trans = {}
  for i in range(n):
    k,v = raw_input().split()
    trans[k] = v.rstrip()
  cnt = int(raw_input())
  res = ""
  for j in range(n):
    a = raw_input().rstrip()
    if a in trans: a = trans[a]
    res += a
  out.append(a)
for o in out: print o

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    org = ''
    dist = ''
    for i in range(n):
        c1, c2 = input().split()
        org += c1
        dist += c2
    m = int(input())
    oSt = ''
    for i in range(m):
        oSt += input()
    print(oSt.translate(str.maketrans(org, dist)))

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8

def registerDictionaryFromTheNumberOf(counts):
    dictionary = {}
    for i in range(counts):
        key, value = input().split(" ")
        dictionary[key] = value
    return dictionary
        
def readCharacterBeforeConversionAsManyAs(counts):
    readString = ""
    for i in range(counts):
        readString += input()
    return readString
    
def convertCharactersByThe(dictionary, target):
    converted = ""
    for index in range(len(list(target))):
        if target[index] in dictionary:
            converted += dictionary[target[index]]
        else:
            converted += target[index]
    return converted
        
while True:
    dictionaryCounts = int(input())
    if dictionaryCounts == 0:
        break
    dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
    original = readCharacterBeforeConversionAsManyAs(int(input()))
    converted = convertCharactersByThe(dictionary, original)
    print(converted)

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8
 
def registerDictionaryFromTheNumberOf(counts):
    dictionary = {}
    for i in range(counts):
        key, value = input().split(" ")
        dictionary[key] = value
    return dictionary
         
def readCharacterBeforeConversionAsManyAs(counts):
    readString = ""
    for i in range(counts):
        readString += input()
    return readString
     
def convertCharactersByThe(dictionary, target):
    converted = ""
    for index in range(len(list(target))):
        if target[index] in dictionary:
            converted += dictionary[target[index]]
        else:
            converted += target[index]
    return converted
         
while True:
    dictionaryCounts = int(input())
    if dictionaryCounts == 0:
        break
    dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
    original = readCharacterBeforeConversionAsManyAs(int(input()))
    converted = convertCharactersByThe(dictionary, original)
    print(converted)

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8
 
def registerDictionaryFromTheNumberOf(counts):
    dictionary = {}
    for i in range(counts):
        key, value = input().strip().split(" ")
        dictionary[key] = value
    return dictionary
         
def readCharacterBeforeConversionAsManyAs(counts):
    readString = ""
    for i in range(counts):
        readString += input()
    return readString
     
def convertCharactersByThe(dictionary, target):
    converted = ""
    for index in range(len(list(target))):
        if target[index] in dictionary:
            converted += dictionary[target[index]]
        else:
            converted += target[index]
    return converted
         
while True:
    dictionaryCounts = int(input())
    if dictionaryCounts == 0:
        break
    dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
    original = readCharacterBeforeConversionAsManyAs(int(input()))
    converted = convertCharactersByThe(dictionary, original)
    print(converted)

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = 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)))

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = 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)))
print()

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = list(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)))

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = 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)), end="")
    print()

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    d = dict([raw_input().split() for _ in range(n)])
    m = int(raw_input())
    s = ''.join([raw_input() for _ in range(m)])
    print ''.join([d[c] if c in d else c for c in s])

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    d = dict([raw_input().split() for _ in range(n)])
    m = int(raw_input())
    s = ''.join([raw_input() for _ in range(m)])
    print ''.join([d.get(c) if c in d else c for c in s])