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: Accepted

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()[0]
    print(oSt.translate(str.maketrans(org, dist)))

Submission status: Accepted

Solution code:
while 1:
    n=input()
    if n==0:break
    table={}
    for i in xrange(n):
        a,b=raw_input().split()
        table[a]=b
    m=input()
    ans=""
    for i in xrange(m):
        s=raw_input()[0]
        if s in table:
            ans+=table[s]
        else:
            ans+=s
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
cin = sys.stdin
while True:
    n = int(cin.readline())
    if n == 0:break
    c = {}
    for _ in range(n):
        a,b = cin.readline().strip().split()
        c[a] = b
    m = int(cin.readline())
    ans = ''
    for _ in range(m):
        a = cin.readline().strip()
        ans+=c[a] if a in c else a
    print(ans)

Submission status: Accepted

Solution code:
import collections
import sys

l = collections.deque(sys.stdin.readlines())
l.pop()
result = ""
while l:
    n = int(l.popleft())
    dict = {}
    s = ""
    for i in range(n):
        key, value = l.popleft().split()
        dict[key] = value
    for i in range(int(l.popleft())):
        key = l.popleft().strip()
        if key in dict:
            s += dict[key]
        else:
            s += key
    result += s + "\n"

print(result, end="")

Submission status: Accepted

Solution code:
while True:
	n = int(input())

	if n == 0:
		break
	
	dic = {}
	for i in range(n):
		pre, pos = input().split()
		dic[pre] = pos.rstrip()

	n = int(input())
	s = ""
	for i in range(n):
		c = input().rstrip()
		if c in dic:
			s += dic[c]
		else:
			s += c

	print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    conv_map = {}
    s = ""
    n=input()
    if n==0:
        break

    for x in xrange(n):
        lst = raw_input().split()
        conv_map[lst[0]] = lst[1]

    m=input()
    tmp=""
    for x in xrange(m):
        tmp=raw_input()[0]
        s += conv_map.get(tmp, tmp)

    print s

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n=int(input())
while(n!=0):
    list={}
    sum=""
    for i in range(n):
        a,b=input().split()
        list[a]=b.rstrip()
    n=int(input())
    for i in range(n):
        s=input().rstrip()
        if s in list:
            sum+=list[s]
        else:
            sum+=s
    print(sum)
    n=int(input())

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    # ??????????????\???
    while True:
        conv_num = int(input().strip())
        if conv_num == 0:
            break
        conv_dict = {}
        for i in range(conv_num):
            from_ch, to_ch = input().strip().split(' ')
            conv_dict[from_ch] = to_ch

        text_len = int(input().strip())
        orig_txt = [input().strip() for _ in range(text_len)]

        # ???????????????
        converted_txt = []
        for c in orig_txt:
            if c in conv_dict:
                converted_txt.append(conv_dict[c])
            else:
                converted_txt.append(c)

        # ???????????¨???
        print('{0}'.format(''.join(map(str, converted_txt))))

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a={}
    for _ in range(n):
        b,c=input().strip().split()
        a[b]=c
    d=''
    for _ in range(int(input())):
        e=input().strip()
        d+=a[e] if e in a else e
    print(d)

Submission status: Accepted

Solution code:
import sys
while True:
    dic = {}
    n = int(input())
    if n == 0:
        sys.exit(0)
    for _ in range(n):
        key, val = input().strip().split()
        dic[key] = val
    m = int(input())
    indata = []
    for i in range(m):
        indata.append(input().strip())
    outdata = []
    for c in indata:
        if c in dic:
            outdata.append(dic[c])
        else:
            outdata.append(c)

    print(''.join(outdata))

Submission status: Accepted

Solution code:
# your code goes here
import sys

while True:
	n = input()
	if n == 0: break
	convDict = {};
	for _ in range(n):
		src, dest = raw_input().split();
		convDict[src] = dest;

	m = input()
	for _ in range(m):
		c = raw_input().rstrip()
		if c in convDict.keys():
			c = convDict[c];
		sys.stdout.write(c)
	print

Submission status: Accepted

Solution code:
ans = ""
while True:
    rev = ""
    n = int(raw_input())
    if n == 0:
        break
    table = {}
    for i in range(0, n):
        line = raw_input().strip().split()
        table[line[0]] = line[1]
    
    m = int(raw_input())
    for i in range(0, m):
        s = raw_input().strip()
        if s in table:
            rev += table[s]
        else:
            rev += s
    ans += rev + "\n"
print ans,

Submission status: Accepted

Solution code:
#!/home/minamo/.pyenv/versions/3.6.1/bin/python
# vim: ft=python
# 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().rstrip()
    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: Accepted

Solution code:
import sys
while True:
    ans = []
    flag=0
    n = int(input())
    if n==0: break
    a=[[i for i in input().split()] for i in range(n)]
    m = int(input())
    for i in range(m):
        ch = input().strip()
        for j in range(n):
            if ch==a[j][0]:
                ans.append(a[j][1])
                flag=1
        if flag!=1:
            ans.append(ch)
        flag=0
            
    for i in range(len(ans)):
        sys.stdout.write(ans[i])
    print()

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys
 
while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    dic = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split(' ')
        dic[k] = v
    n = int(sys.stdin.readline().rstrip())
    ret = []
    for i in range(n):
        d = sys.stdin.readline().rstrip()
        if d in dic.keys():
            ret.append(dic[d])
        else:
            ret.append(d)
    print(''.join(ret))

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    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(sys.stdin.readline().rstrip())):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Submission status: Accepted

Solution code:
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(sys.stdin.readline().rstrip())):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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 = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d.get(a, a)
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = []
    for _ in range(m):
        a = input().strip()
        ans.append(d.get(a, a))
    print("".join(ans))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = ""
    for _ in range(m):
        a = input().strip()
        try:
            ans += d[a]
        except:
            ans += a
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d[a] if a in d else a
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = ""
    for _ in range(m):
        a = input().strip()
        if a in d:
            ans += d[a]
        else:
            ans += a
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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.get(a, a) for a in tmp]
    print("".join(ans))

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
n = input()

while(n != 0):
    convTable = {}
    
    for i in range(n):
        t = raw_input().split()
        convTable[t[0]] = t[1]
    
    n = input()
    for i in range(n):
        t = raw_input().split()
        if t[0] in convTable:
            sys.stdout.write(convTable[t[0]])
        else:
            sys.stdout.write(t[0])
    sys.stdout.write("\n")
    n = input()

Submission status: Accepted

Solution code:
# coding: utf-8

while True:
	n = int(raw_input())
	if n == 0:
		break
	henkan = []
	for i in range(n):
		henkan.append(raw_input().split())

	m = int(raw_input())
	ans = ""
	for i in range(m):
		c = raw_input().split()
		for j in range(len(henkan)):
			if c[0] == henkan[j][0]:
				c[0] = henkan[j][1]
				break
		ans += c[0]
	print ans

Submission status: Accepted

Solution code:
# coding: utf-8

while True:
	n = int(raw_input())
	if n == 0:
		break
	henkan = []
	for i in range(n):
		henkan.append(raw_input().split())

	m = int(raw_input())
	ans = ""
	for i in range(m):
		c = raw_input().split()
		for j in range(len(henkan)):
			if c[0] == henkan[j][0]:
				c[0] = henkan[j][1]
				break
		ans += c[0]

	print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

while True:
	n = int(raw_input())
	if n == 0:
		break
	else:
		henkan = []
		for i in range(n):
			henkan.append(raw_input().split())
		#print(henkan)

		m = int(raw_input())
		ans = ""
		for i in range(m):
			c = raw_input().split()
			for j in range(len(henkan)):
				if c[0] == henkan[j][0]:
					#print("{:} -> {:}".format(henkan[j][0], henkan[j][1]))
					c[0] = henkan[j][1]
					break
			ans += c[0]

		print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    converter = {}
    for _ in range(n):
        k, v = input().split()
        converter[k] = v

    m = int(input())
    ans = []
    for _ in range(m):
        v = input().strip()
        try:
            ans.append(converter[v])
        except:
            ans.append(v)

    print("".join(ans))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    data = {}
    for i in range(n):
        a,b = input().strip().split()
        data[a] = b
    ans_data = ''

    for i in range(int(input())):
        c = input().strip()
        ans_data += data[c] if c in data else c
    print(ans_data)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  D = dict()
  for _ in range(n):
    k,v = input().rstrip().split()
    D[k] = v
  m = int(input())
  ans = ""
  for _ in range(m):
    s = input().rstrip()
    if s in D:
      s = D[s]
    ans = ans + s
  print(ans)

Submission status: Accepted

Solution code:
import sys
s=sys.stdin.readline
while 1:
 n=int(s())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=s().strip().split()
  d[k]=v
 a=''
 for _ in[0]*int(s()):
  a+=d.get(*[s().strip()]*2)
 print(a)

Submission status: Accepted

Solution code:
import sys
s=sys.stdin.readline
while 1:
 n=int(s())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=s().strip().split()
  d[k]=v
 print(''.join(d.get(*[s().strip()]*2)for _ in[0]*int(s())))

Submission status: Accepted

Solution code:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  k,v=s().strip().split()
  d[k]=v
 print(''.join(d.get(*[s().strip()]*2)for _ in[0]*int(s())))

Submission status: Accepted

Solution code:
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(''.join(d.get(*[s().strip()]*2)for _ in[0]*int(s())))

Submission status: Accepted

Solution code:
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(''.join(d.get(*[s()[0]]*2)for _ in[0]*int(s())))

Submission status: Accepted

Solution code:
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='')

Submission status: Accepted

Solution code:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  e=s()
  d[e[0]]=e[2]
 print(''.join(d.get(*[s()[0]]*2)for _ in[0]*int(s())))

Submission status: Accepted

Solution code:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):e=s();d[e[0]]=e[2]
 print(''.join(d.get(*[s()[0]]*2)for _ in[0]*int(s())))

Submission status: Accepted

Solution code:
# 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]
		if a in tbl: ans += tbl[a]
		else: ans += a
	print(ans)

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

Solution code:
while True:
  count = int(input())
  if count == 0:break
  else:
    a,b,c,d = [],[],[],[]
    for i in range(count):
      g = map(str,raw_input().split())
      a.append(g[0])
      b.append(g[1])
    tugi = int(input())
    for j in range(tugi):
      r = raw_input()
      for x in range(count):
        if r[0] == a[x]:
          c.append(b[x])
          break
      else: c.append(r[0])
    print ''.join(c)

Submission status: Accepted

Solution code:
def foo(infile, outfile, n):
    mapping = {}
    for i in range(n):
        a, b = infile.readline().split()
        mapping[a]=b
    m = int(infile.readline())

    for j in xrange(m):
        x = infile.readline().split()[0]
        outfile.write(mapping.get(x, x))
    print >> outfile


def run(infile, outfile):
    while True:
        n = int(infile.readline())
        if n == 0:
            break
        foo(infile, outfile, n)


if __name__ == "__main__":
    import sys
    run(sys.stdin, sys.stdout)

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:
        break
    dic={}
    for i in range(n):
        pre,pos=raw_input().split()
        dic[pre]=pos.rstrip()
    n=input()
    s=""
    for i in range(n):
        c=raw_input().rstrip()
        if c in dic:
            s+=dic[c]
        else:
            s+=c
    print s

Submission status: Accepted

Solution code:
import sys

while 1:
    n = int(raw_input())
    if n == 0: break

    map = {}
    for i in range(n):
        vs = raw_input().split()
        map[vs[0]] = vs[1]

    n = int(raw_input())
    for i in range(n):
        ch = raw_input().strip()
        e = map.get(ch)
        if e is None:
            e = ch
        sys.stdout.write(e)
    sys.stdout.write('\n')

Submission status: Accepted

Solution code:
while 1:
    n=input()
    if n==0:break
    s=""
    d={}
    for i in range(n):
        a=raw_input().split()
        d[a[0]]=a[1]
    for i in range(input()):
        b=raw_input().split()
        if b[0] in d:
            s+=d.get(b[0])
        else:
            s+=b[0]
    print s

Submission status: Accepted

Solution code:
while True:
    a=input();t={};s=""
    if a==0:break
    for i in range(a):
        q=raw_input().split()
        t[q[0]]=q[1]
    for j in range(input()):
        q=raw_input().strip()
        if q in t: s+=t[q]
        else: s+=q
    print s

Submission status: Accepted

Solution code:
while True:
    a=input();t={};s=""
    if a==0:break
    for i in range(a):
        q=raw_input().split()
        t[q[0]]=q[1]
    for j in range(input()):
        q=raw_input().strip()
        s=s+t[q] if q in t else s+q
    print s

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n == 0:
        break
    change = dict()
    for i in range(n):
        line = raw_input().split()
        change[line[0]] = line[1]

    n = input()
    s = ""
    for i in range(n):
        line = raw_input().strip()
        s += (change[line] if line in change else line)
    print s

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n == 0: break

    d = {}
    for _ in range(n):
        a, b = raw_input().split()
        d[a] = b

    m = input()

    a = []

    for _ in range(m):
        c = raw_input().strip()
        if c in d:
            a.append(d[c])
        else:
            a.append(c)

    print ''.join(a)

Submission status: Accepted

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 = ''
    for _ in range(m):
        b = raw_input().split()
        if b[0] in d:
            s += d[b[0]]
        else:
            s += b[0]
    print s

Submission status: Accepted

Solution code:
import string

n = int(raw_input())
while n != 0:
	f = []
	t = []
	for i in xrange(n):
		l = raw_input().split()
		f.append(l[0])
		t.append(l[1])
	d = string.maketrans(''.join(f), ''.join(t))
	s = []
	for i in xrange(int(raw_input())):
		s.append(raw_input().strip())
	print ''.join(s).translate(d)
	n = int(raw_input())

Submission status: Accepted

Solution code:
import string

n = int(raw_input())
while n != 0:
	l  = [raw_input().split() for i in xrange(n)]
	f = [i for i,j in l]
	t = [j for i,j in l]
	d = string.maketrans(''.join(f), ''.join(t))
	s = [raw_input().strip() for i in xrange(int(raw_input()))]
	print ''.join(s).translate(d)
	n = int(raw_input())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n==0: break
    r = {}; p = "";
    for i in xrange(n):
        a,b=raw_input().split()
        r[a]=b
    m = input()
    for i in xrange(m):
        s = raw_input()[0]
        p += r.get(s,s)
    print p

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n == 0:
        break
    dic = {}    
    for _ in xrange(n):
        a, b = raw_input().split()
        dic[a] = b
    f = lambda x:x if x not in dic else dic[x]
    print "".join(f(raw_input().strip()) for _ in xrange(input()))

Submission status: Accepted

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(cnt):
    a = raw_input().rstrip()
    if a in trans: a = trans[a]
    res += a
  out.append(res)
for o in out: print o

Submission status: Accepted

Solution code:
while 1:
	n=input()
	if n==0:break
	dic={}
	for i in range(n):
		k,v=raw_input().split()
		dic[k]=v
	n=input()
	ans=""
	for i in range(n):
		a=raw_input()[0]
		try:ans+=dic[a]
		except:ans+=a
	print ans

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    word1 = word2 = ""
    for i in range(n):
        a, b = input().split()
        word1 += a
        word2 += b
    q = int(input())
    s = ""
    for i in range(q):
        s+=input().rstrip()
    print(s.translate(str.maketrans(word1, word2)))

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    dic = dict()
    for i in range(0,n):
        w1,w2 = input().split()
        dic[w1] = w2
    n = int(input())
    s = ""
    for i in range(0,n):
        w = input()[0]
        if dic.get(w) != None:
            s += dic.get(w)
        else:
            s += w
    print(s)

Submission status: Accepted

Solution code:
#変換表の数を入力し０なら処理を終わる
while True:
    a = int(input())
    if a == 0:break

    #空の辞書とリストを作成する
    di = {}
    line = []
    
    #変換表を入力し、辞書に入れ、キーをリストに入れる
    for _ in range(a):
        s1,s2 = input().split()
        di[s1] = s2
        line.append(s1)
        
    #文字を入力し変換表に含まれているなら変換し入っていなかったらそのまま出力する
    for _ in range(int(input())):
        l = input().rstrip()
        if l in line:print(di[l],end="")
        else:print(l,end="")
    print()

Submission status: Accepted

Solution code:
while True:
	n = int(input())
	if n == 0:
		break
	dict = {}
	for _ in range(n):
		a = list(input().split())
		dict[a[0]] = a[1]
#	print(dict)
	m = int(input())
	s = ''
	for _ in range(m):
		j = input().strip()
		if j in dict:
			j = dict[j]
		s = s + j
	print(s)