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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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()
        ans += d.get(a, a)
    print(ans)

Submission status: Wrong Answer

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()
        if t in convTable:
            sys.stdout.write(convTable[t])
        else:
            sys.stdout.write(t)
    
    n = input()

Submission status: Wrong Answer

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()
        if t in convTable:
            sys.stdout.write(convTable[t])
        else:
            sys.stdout.write(t)
    sys.stdout.write("\n")
    n = input()

Submission status: Wrong Answer

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()
		for j in range(len(henkan)):
			if c == henkan[j][0]:
				c = henkan[j][1]
				break
		ans += c

	print(ans)

Submission status: Wrong Answer

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())
	print(henkan)

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

	print(ans)

Submission status: Wrong Answer

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()
			for j in range(len(henkan)):
				if c == henkan[j][0]:
					c = henkan[j][1]
					break
			ans += c

		print(ans)

Submission status: Wrong Answer

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()
			for j in range(len(henkan)):
				if c == henkan[j][0]:
					c = henkan[j][1]
					break
			ans += c

		print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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()
        try:
            ans.append(converter[v])
        except:
            ans.append(v)

    print("".join(ans))

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    table = dict()
    for i in range(n):
        f,t = input().split(' ')
        table[f] = t
    m = int(input())
    data = ''
    for j in range(m):
        s = input()
        if s in table:
            data += table[s]
        else:
            data += s
    print(data)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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()
  print(d[e]if e in d else e,end='')
 print()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N_change = int(input())
change = [[i for i in input().split()] for i in range(N_change)]
N_data = int(input())
ans = ""

for i in range(N_data):
    a = input()
    for j in range(N_change):
        if a == change[j][0]:
            a = change[j][1]
            break
    ans += a

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


while 1:
    N_change = int(input())
    if N_change == 0:
        break
    change = [[i for i in input().split()] for i in range(N_change)]
    N_data = int(input())
    ans = ""

    for i in range(N_data):
        a = input()
        for j in range(N_change):
            if a == change[j][0]:
                a = change[j][1]
                break
        ans += a

    print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    po = {}
    for i in range(n):
        key,value = input().split()
        po[key] = value
    m = int(input())
    string = []
    for i in range(m):
        letter = input()
        if letter in po.keys():
            letter = po[letter]
        string.append(letter)
    print("".join(string))

Submission status: Wrong Answer

Solution code:
num_of_data = 1
while True:
    n = int(input())
    if n == 0 or num_of_data > 5:
        break
        
    bef = []
    aft = []

    for i in range(0, n):
        b, a = list(input().split())
        bef.append(b)
        aft.append(a)

    m = int(input())
    if m > 100000:
        break
        
    c = []

    for i in range(0, m):
        moji = input()
        c.append(moji)

    for i in range(0, m):
        flag = 0
        for j in range(0, n):
            if c[i] == bef[j]:
                flag = 1
                ind = j

        if flag == 1:
            print(aft[ind], end = '')
        else :
            print(c[i], end = '')

    print('')
    num_of_data += 1

Submission status: Wrong Answer

Solution code:
num_of_data = 1
while True:
    n = int(input())
    if n == 0 or num_of_data > 5:
        break
        
    bef = []
    aft = []

    for i in range(0, n):
        b, a = list(input().split())
        bef.append(b)
        aft.append(a)

    m = int(input())
    if m > 100000:
        break
        
    for i in range(0, m):
        moji = input()

        flag = 0
        for j in range(0, n):
            if bef[j] == moji:
                flag = 1
                ind = j
        if flag == 1:
            print(aft[ind], end = '')
        else :
            print(moji, end = '')

    print('')
    num_of_data += 1

Submission status: Wrong Answer

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

    d = dict()
    res = ''

    for i in range(N):
        line = input()

        d[line[0]] = line[-1]

    M = int(input())

    for i in range(M):
        line = input()
        if line in d:
            res += d[line]
        else:
            res += line

    print(res)

Submission status: Wrong Answer

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    
    d = dict()
    res = ''
    
    for i in range(N):
        line = input()
    
        d[line[0]] = line[-1]
    
    M = int(input())
    
    for i in range(M):
        line = input()
        if line in d:
            res += d[line]
        else:
            res += line
    
    print(res)

Submission status: Wrong Answer

Solution code:
d = dict()

while True:
    N = int(input())
    if N == 0:
        break

    res = ''

    for i in range(N):
        line = input()

        d[line[0]] = line[-1]

    M = int(input())

    for i in range(M):
        line = input()
        if line in d:
            res += d[line]
        else:
            res += line

    print(res)

Submission status: Wrong Answer

Solution code:

while True:
    d = dict()
    s = set()

    N = int(input())
    if N == 0:
        break

    res = ''

    for i in range(N):
        line = input()

        d[line[0]] = line[-1]

    M = int(input())

    for i in range(M):
        line = input()
        if line in d and line not in s:
            res += d[line]
            s.add(line)
        else:
            res += line

    print(res)

Submission status: Wrong Answer

Solution code:
d = dict()
s = set()

while True:
    N = int(input())
    if N == 0:
        break

    res = ''

    for i in range(N):
        line = input()

        d[line[0]] = line[-1]

    M = int(input())

    for i in range(M):
        line = input()
        if line in d and line not in s:
            res += d[line]
            s.add(line)
        else:
            res += line

    print(res)

Submission status: Wrong Answer

Solution code:
d = dict()
s = set()

while True:
    N = int(input())
    if N == 0:
        break

    res = ''

    for i in range(N):
        line = input()

        d[line[0]] = line[-1]

    M = int(input())

    for i in range(M):
        line = input()
        if line in d and line not in s:
            res += d[line]
            s.add(d[line])
        else:
            res += line

    print(res)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    A = []
    B = []
    for i in range(n):
       a,b = list(map(str,input().split(" ")))
       A.append(a)
       B.append(b)
    
    N = int(input())
    Data = []
    for i in range(N):
        Data.append(str(input()))
              
    for i in range(N):
        for j in range(n):
            if Data[i] == A[j]:
                Data[i] = B[j]
                break
    
    print("".join(Data))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
while True:
    n = int(input())    
    if not n:
        break
    
    change = {}
    for _ in range(n):
        a = input().split()
        change[a[0]] = a[1]
    m = int(input())
    out = []
    for m in range(m):
        po = input()
        if po in change:
            out.append(change[po])
        else:
            out.append(po)
    print(*out,sep="")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
while True:
    n = int(input())    
    if not n:
        break
    
    change = {}
    for _ in range(n):
        a = input().split()
        change[a[0]] = a[1]
    m = int(input())
    for m in range(m):
        po = input()
        if po in change:
            print(change[po],end="")
        else:
            print(po,end="")
    print("")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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()[:-1]]*2)for _ in[0]*int(s())))

Submission status: Wrong Answer

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()
		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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import string
str = []
while True:
    n = input()
    if n == 0:
        break
    replList = []
    p = 0
    while p != n:
        source = raw_input()
        source = source.split()
        replList.append(source)
        p += 1

    
    p = 0
    m = input()
    s = []
    while p != m:
        temp = raw_input()
        for i in replList:
            if i[0] == temp:
                temp = i[1]
                #replList.remove(i)
        s.append(temp)
    
        p += 1

    temp = ''.join(s)
    str.append(temp)
for i in str:
    print i

Submission status: Wrong Answer

Solution code:
import string
str = []
while True:
    n = input()
    if n == 0:
        break
    replList = []
    p = 0
    while p != n:
        source = raw_input()
        source = source.split()
        replList.append(source)
        p += 1

    
    p = 0
    m = input()
    s = []
    while p != m:
        temp = raw_input()
        for i in replList:
            if i[0] == temp:
                temp = i[1]
                replList.remove(i)
        s.append(temp)
    
        p += 1

    temp = ''.join(s)
    str.append(temp)
for i in str:
    print i

Submission status: Wrong Answer

Solution code:
while True:
  a=[]
  b=[]
  c=[]
  count = int(input())
  if count == 0:break
  for i in range(count):
    x,y = map(str,raw_input().split())
    a.append(x)
    b.append(y)
  count2 = int(input())
  for i in range(count2):
    t = raw_input()
    c.append(t)
  for i in range(count2):
    for j in range(count):
      if c[i] == a[j]:
        c[i]=b[j]
        break
  print ''.join(c)

Submission status: Wrong Answer

Solution code:
d = dict()
n = int(input())
for i in range(n):
  a = raw_input().split()
  d[a[0]] = a[1]
m = int(input())
for i in range(m):
  c = raw_input()
  c = d.get(c,c)
  print(c,)
print()

Submission status: Wrong Answer

Solution code:
import sys

while True:
    n = input()

    if n != 0:
        
        table = [['',''] for i in range(n)]
        for i in xrange(n):
           table[i][0],table[i][1] = map(str, raw_input().split(' '))
        
        table0 = [table[i][0] for i in range(n)]
        table1 = [table[i][1] for i in range(n)]
        
        
        m = input()
        
        array = []
        for i in xrange(m):
           array.append(raw_input())
        
        array2 = [ '' for i in range(len(array))]
        
        for i in xrange(len(array)):
            if array[i] in table0:
                array2[i] = table1[table0.index(array[i])]
            else :
                array2[i] = array[i]
        
        for i in xrange(len(array)):
            sys.stdout.write(array2[i])
        sys.stdout.write('\n')
        
    elif n == 0:
        break

Submission status: Wrong Answer

Solution code:
import sys

while True:
    n = input()

    if n != 0:
        
        table = [['',''] for i in range(n)]
        for i in xrange(n):
           table[i][0],table[i][1] = map(str, raw_input().split(' '))
        
        table0 = [table[i][0] for i in range(n)]
        table1 = [table[i][1] for i in range(n)]
        
        
        m = input()
        
        array = []
        for i in xrange(m):
           array.append(raw_input())
        
        array2 = [ '' for i in range(len(array))]
        
        for i in xrange(len(array)):
            if array[i] in table0:
                array2[i] = table1[table0.index(array[i])]
            else :
                array2[i] = array[i]
        
        print ''.join(array2)        
    elif n == 0:
        break

Submission status: Wrong Answer

Solution code:
while True:
    n = input()

    if n != 0:
        
        table = [['',''] for i in range(n)]
        for i in xrange(n):
           table[i][0],table[i][1] = map(str, raw_input().split(' '))
        
        table0 = [table[i][0] for i in range(n)]
        table1 = [table[i][1] for i in range(n)]
        
        
        m = input()
        
        array = []
        for i in xrange(m):
           array.append(raw_input())
        
        array2 = [ '' for i in range(len(array))]
        
        for i in xrange(len(array)):
            if array[i] in table0:
                array2[i] = table1[table0.index(array[i])]
            else :
                array2[i] = array[i]
        
        print ''.join(array2)        
    elif n == 0:
        break

Submission status: Wrong Answer

Solution code:
while True:
    n = input()

    if n != 0:
        
        table = [['',''] for i in range(n)]
        for i in xrange(n):
           table[i][0],table[i][1] = map(str, raw_input().split(' '))
        
        table0 = [table[i][0] for i in range(n)]
        table1 = [table[i][1] for i in range(n)]
        
        
        m = input()
        
        array = []
        for i in xrange(m):
           array.append(raw_input())
        
        array2 = [ '' for i in range(len(array))]
        
        for i in xrange(len(array)):
            if array[i] in table0:
                array2[i] = table1[table0.index(array[i])]
            else :
                array2[i] = array[i]
        
        print ''.join(array2)
    elif n == 0:
        break

Submission status: Wrong Answer

Solution code:
import sys

n = int(raw_input())
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()
    e = map.get(ch)
    if e is None:
        e = ch
    sys.stdout.write(e)
sys.stdout.write('\n')

Submission status: Wrong Answer

Solution code:
print "aBC5144aba"

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
while 1:
    n=int(raw_input())
    if n==0: break
    conv={}
    for i in range(n):
        k,v=raw_input().split()
        conv[k]=v
    m=int(raw_input())
    t=[raw_input() for i in range(m)]
    ans=['']*m
    for i,v in enumerate(t):
        if conv.has_key(v):
            ans[i]=conv[v]
        else:
            ans[i]=v

    print "".join(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
while 1:
    n=int(raw_input())
    if n==0: break
    dic={}
    for i in range(n):
        k,v=raw_input().split()
        dic[k]=v
    m=int(raw_input())
    ans=''
    for i in range(m):
        v=raw_input()
        if v in dic:
            ans+=dic[v]
        else:
            ans+=v
    print ans

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
while 1:
    n=int(raw_input())
    if n==0: break
    dic={}
    for i in range(n):
        k,v=raw_input().split()
        dic[k]=v
    m=int(raw_input())
    ans=''
    for i in range(m):
        v=raw_input()
        if v in dic:
            ans+=dic[v]
            del dic[v]
        else:
            ans+=v
    print ans

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if not n: break
    conv={}
    for i in range(n):
        k,v=raw_input().split()
        conv[k]=v
    ans=''
    m=input()
    for i in range(m):
        c=raw_input()
        print c,conv
        if conv.has_key(c):
            ans+=conv[c]
            del conv[c]
        else:
            ans+=c
    print ans

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if not n: break
    conv={}
    for i in range(n):
        k,v=raw_input().split()
        conv[k]=v
    ans=''
    m=input()
    for i in range(m):
        c=raw_input()
        if conv.has_key(c):
            ans+=conv[c]
            del conv[c]
        else:
            ans+=c
    print ans

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if not n: break
    conv={}
    for i in range(n):
        k,v=raw_input().split()
        conv[k]=v
    ans=''
    m=input()
    for i in range(m):
        c=raw_input()
        if conv.has_key(c):
            ans+=conv[c]
            # del conv[c]
        else:
            ans+=c
    print ans

Submission status: Wrong Answer

Solution code:
n = input()

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

m = input()

a = []

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

print ''.join(a)

Submission status: Wrong Answer

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()
        if c in d:
            a.append(d[c])
        else:
            a.append(c)

    print ''.join(a)

Submission status: Wrong Answer

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()
        if c in d:
            a.append(d[c])
        else:
            a.append(c)

    print ''.join(a)

Submission status: Wrong Answer

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()
		if a in dict:
			res += dict[a]
		else:
			res += a
	print res

Submission status: Wrong Answer

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()
        p += r[s] if s in r else s
    print p

Submission status: Wrong Answer

Solution code:
dic = {}
for _ in xrange(input()):
    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: Wrong Answer

Solution code:
while True:
    trans = {}
    cnt = int(raw_input())
    if cnt == 0: break
    while cnt > 0:
        k,v = raw_input().split(' ')
        trans[k] = v
        cnt -= 1
    cnt = int(raw_input())
    ans = ''
    while cnt > 0:
        load = raw_input()
        if load in trans.keys(): load = trans[load]
        ans += load
        cnt -= 1
    print ans

Submission status: Wrong Answer

Solution code:
ans = []
append = ans.append
while True:
    trans = {}
    cnt = int(raw_input())
    if cnt == 0: break
    while cnt > 0:
        k,v = raw_input().split(' ')
        trans[k] = v
        cnt -= 1
    cnt = int(raw_input())
    ans = ''
    while cnt > 0:
        load = raw_input()
        if load in trans.keys(): load = trans[load]
        ans += load
        cnt -= 1
    append(ans)
for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
out = []
append = out.append
while True:
    trans = {}
    cnt = int(raw_input())
    if cnt == 0: break
    while cnt > 0:
        k,v = raw_input().split(' ')
        trans[k] = v
        cnt -= 1
    cnt = int(raw_input())
    ans = ''
    while cnt > 0:
        load = raw_input()
        if load in trans.keys(): load = trans[load]
        ans += load
        cnt -= 1
    append(ans)
for i in out:
    print i

Submission status: Wrong Answer

Solution code:
out = []
append = out.append
cnt = int(raw_input())
while cnt > 0:
    trans = {}
    while cnt > 0:
        k,v = raw_input().split(' ')
        trans[k] = v
        cnt -= 1
    leng = int(raw_input())
    ans = ''
    while leng > 0:
        load = raw_input()
        if load in trans.keys(): load = trans[load]
        ans += load
        leng -= 1
    print ans
    cnt = int(raw_input())

Submission status: Wrong Answer

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(a)
for o in out: print o

Submission status: Wrong Answer

Solution code:
cipher = {}
ans = ""
for i in range(input()):
	tmp = raw_input().split()
	cipher[tmp[0]] = tmp[1]
for j in range(input()):
	s = raw_input()
	if s in cipher:
		ans += cipher[s]
	else:
		ans += s
print ans

Submission status: Wrong Answer

Solution code:
while True:
	cipher = {}
	ans = ""
	n = input()
	if n == 0: break
	for i in range(n):
		tmp = raw_input().split()
		cipher[tmp[0]] = tmp[1]
	for j in range(input()):
		s = raw_input()
		if s in cipher:
			ans += cipher[s]
		else:
			ans += s
	print ans

Submission status: Accepted

Solution code:
def convert(infile, outfile, n):
    dictionary = {}
    for i in range(n):
        key, val = infile.readline().split()
        dictionary[key]=val
    m = int(infile.readline())
    for j in range(m):
        x = infile.readline().split()[0]
        outfile.write(dictionary.get(x, x))
    print >> outfile
 
def run(infile, outfile):
    while True:
        n = int(infile.readline())
        if n == 0:
            break
        convert(infile, outfile, n)
 
if __name__ == "__main__":
    import sys
    run(sys.stdin, sys.stdout)

Submission status: Accepted

Solution code:
while True:
    try:
        n = input()
        if n == 0:
            break
        else:
            before = []
            after = []
            for i in range(n):
                lst = raw_input().split(' ')
                before.append(lst[0])
                after.append(lst[1])
            m = input()
            ans = ''
            for i in range(m):
                value = raw_input()[0]
                try:
                    ans += after[before.index(value)]
                except ValueError:
                    ans += value
            print ans
    except EOFError:
        break

Submission status: Accepted

Solution code:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

while(True):
    after_string_list = []
    before_string_list = []
    convert_list = {}

    n = int(input())
    if n == 0:
        break

    for i in range(n):
        convert = list(input().split())
        convert_list[convert[0]] = convert[1]

    m = int(input())
    for i in range(m):
    	before_string_list.append(input().rstrip())

    for c in before_string_list:
    	if c in convert_list:
    		after_string_list.append(convert_list[c])
    	else:
    		after_string_list.append(c)
    print("".join(after_string_list))

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-

import sys

line_count = 0
next_count = 0
convert_dic = {}
inputs = []
status = 0
for line in sys.stdin:
    line = line.rstrip()
    if status == 0:
        next_count = int(line)
        status = 1
        continue
    if status == 1:
        x1, x2 = line.split(" ")
        convert_dic[x1] = x2
        next_count -= 1
        if next_count == 0:
            status = 2
            continue
    if status == 2:
        next_count = int(line)
        status = 3
        continue
    if status == 3:
        if convert_dic.get(line) is not None:
            line = convert_dic[line]
        inputs.append(line)
        next_count -= 1
        if next_count == 0:
            print "".join(inputs)
            inputs = []
            status = 0
            convert_dic = {}

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    converter = {}
    for _ in range(n):
        pre, post = f.readline().strip().split()
        converter[pre] = post
    m = int(f.readline())
    for _ in range(m):
        c = f.readline().strip()
        print(converter[c] if c in converter else c, end='')
    print()

Submission status: Accepted

Solution code:
#!/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().split()[0]
        ret += dic.get(s, s)

    print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	n = int(raw_input())
	if n == 0:
		break
	
	re = []
	for _ in xrange(n):
		re.append(raw_input())
	
	n = int(raw_input())
	source = []
	for _ in xrange(n):
		source.append(raw_input().split()[0])
	
	for var in re:
		a,b = map(str,var.split())
		for i in xrange(len(source)):
			if source[i] == a:
				source[i] = b + "$"
	
	code = ""
	for i in xrange(len(source)):
		code += source[i][:1]
	
	print code

Submission status: Accepted

Solution code:
while(1):
  table = {}
  output = ''
  table_number = int(input())
  if table_number == 0:
    break
  for i in xrange(table_number):
    a, b = raw_input().split()
    table[a] = b
  string_number = int(input())
  for i in xrange(string_number):
    string = raw_input()[0]
    if string in table:
      output += table[string]
    else:
      output += string
  print output