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

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()
                try:
                    ans += after[before.index(value)]
                except ValueError:
                    ans += value
            print ans
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import sys
f = sys.stdin

n = int(f.readline())
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: Wrong Answer

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
    print(dic)
    ret = ''

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

    print(ret)

Submission status: Wrong Answer

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
    print(dic)
    ret = ''

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

    print(ret)

Submission status: Wrong Answer

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()
        ret += dic.get(s, s)

    print(ret)

Submission status: Wrong Answer

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  S = []
  while n > 0:
    line = input()
    s = line.split()
    S.append(s)
    n -= 1
  _ = ''
  N = int(input())
  while N > 0:
    t = input()
    for i in S:
      if i[0] == t:
        t = i[1]
        break
    _ = _ + t
    N -= 1
  print(_)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    a = []
    b = []
    for i in range(n):
        ta, tb = raw_input().split()
        a.append(ta)
        b.append(tb)
    n2 = int(raw_input())
    t_ans = []
    for i in range(n2):
        temp = raw_input()
        for i in range(n):
            if a[i] == temp:
                temp = b[i]
        t_ans.append(temp)

    ans = ''.join(t_ans)
    print ans

Submission status: Wrong Answer

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    a = []
    b = []
    for i in range(n):
        ta, tb = raw_input().split()
        a.append(ta)
        b.append(tb)
    n2 = int(raw_input())
    t_ans = []
    for i in range(n2):
        temp = raw_input()
        for i in range(n):
            if a[i] == temp:
                temp = b[i]
        t_ans.append(temp)

    ans = ''.join(t_ans)
    print "%s" % ans

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if n==0:break
    before=[]
    after=[]
    en=[raw_input().split() for _ in xrange(n)]
    for i in xrange(n):
        before.append(en[i][0])
        after.append(en[i][1])
    m=input()
    ans=""
    for i in xrange(m):
        s=raw_input()
        if s in before:
            for j in xrange(len(before)):
                if before[j]==s:
                    ans+=after[j]
                    break
        else:
            ans+=s
    print(ans)

Submission status: Wrong Answer

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()
        if s in table:
            ans+=table[s]
        else:
            ans+=s
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = {}
for i in range(N):
    key, value = input().split()
    dic[key] = value

M = int(input())
strs = []
for i in range(M):
    strs.append(input())

for s in strs:
    print(dic.get(s, s), end='')
print()

Submission status: Wrong Answer

Solution code:
def solve(N):
    dic = {}
    for i in range(N):
        key, value = input().split()
        dic[key] = value

    M = int(input())
    strs = []
    for i in range(M):
        strs.append(input())

    for s in strs:
        print(dic.get(s, s), end='')
    print()

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

Submission status: Wrong Answer

Solution code:
conv = []
chan = []

b = int(input())
for i in range(b):
    conv.append(input(). split())
a = int(input())
for i in range(a):
    chan.append(input())

for i in range(a):
    for j in range(b):
        if chan[i] == conv[j][0]:
            chan[i] = conv[j][1]
            break
    print(chan[i], end = '')

print("")

Submission status: Wrong Answer

Solution code:
while True:
    conv = []
    chan = []

    b = int(input())
    if b == 0:
        break
    for i in range(b):
        conv.append(input(). split())
    a = int(input())
    for i in range(a):
        chan.append(input())

    for i in range(a):
        for j in range(b):
            if chan[i] == conv[j][0]:
                chan[i] = conv[j][1]
                break
        print(chan[i], end = '')

    print("")

Submission status: Wrong Answer

Solution code:
N=int(input())
b={}
for i in range(N):
	a=input().split()
	b[a[0]]=a[1]

M=int(input())
ans=""
for i in range(M):
	c=input()
	if c in b:
		ans+=b[c]
	else:
		ans+=c
print(ans)

Submission status: Wrong Answer

Solution code:
answer=""
while True:
	try:
		N=int(input())
	except:
		break
	if N==0:
		break
	if answer!="":
		answer+="\n"
	b={}
	for i in range(N):
		a=input().split()
		b[a[0]]=a[1]
	M=int(input())
	
	ans=""
	for i in range(M):
		c=input()
		if c in b:
			ans+=b[c]
		else:
			ans+=c
	answer+=ans
print(answer)

Submission status: Wrong Answer

Solution code:
conv_map = {}
str_result = ""

while True:
    conv_map = {}
    str_result = ""
    n=input()
    if n==0:
        break

    for idx in range(0, n):
        lst = raw_input().split()
        conv_map[lst[0]] = lst[1]

    m=input()
    tmp=""
    for idx in range(0, m):
        tmp=raw_input()
        str_result += conv_map.get(tmp, tmp)

    print str_result

Submission status: Wrong Answer

Solution code:
conv_map = {}
str_result = ""
 
while True:
    conv_map = {}
    str_result = ""
    n=input()
    if n==0:
        break
 
    for idx in range(0, n):
        lst = raw_input().split()
        conv_map[lst[0]] = lst[1]
 
    m=input()
    tmp=""
    for idx in range(0, m):
        tmp=raw_input()
        if tmp in conv_map:
            str_result += conv_map[tmp]
        else:
            str_result += tmp
 
    print str_result

Submission status: Wrong Answer

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()
        s += conv_map.get(tmp, tmp)

    print s

Submission status: Wrong Answer

Solution code:
x = int(input())
i = 0
dcl = dict()
while True:
    inp = list(map(str, input().split()))
    dcl[inp[0]] = inp[1]
    i += 1
    if i == x:
        break

x = int(input())
i = 0
ans = ""
while True:
    y = str(input())
    if y in dcl:
        ans += dcl[y]
    else:
        ans += y

    i += 1
    if i == x:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
x = int(input())
i = 0
dcl = dict()
if x == 0:
    pass
else:
    while True:
        inp = list(map(str, input().split()))
        dcl[inp[0]] = inp[1]
        i += 1
        if i == x:
            break

    x = int(input())
    i = 0
    ans = ""
    while True:
        y = str(input())
        if y in dcl:
            ans += dcl[y]
        else:
            ans += y

        i += 1
        if i == x:
            break
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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())
        if y in dcl:
            ans += dcl[y]
        else:
            ans += y
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
B = []
for i in range(n):
 a, b = input().split()
 A.append(a)
 B.append(b)
n = int(input())
for i in range(n):
 x = input()
 if x in A:
  ind = A.index(x)
  x = B[ind]
 print(x, end = '')
print()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
B = []
for i in range(n):
 a, b = input().split()
 A.append(a)
 B.append(b)
n = int(input())
s = ''
for i in range(n):
 x = input()
 if x in A:
  ind = A.index(x)
  x = B[ind]
 s += x
print(s)

Submission status: Wrong Answer

Solution code:

n = int(input())
while n != 0:
 A = []
 B = []
 for i in range(n):
  a, b = input().split()
  A.append(a)
  B.append(b)
 n = int(input())
 s = ''
 for i in range(n):
  x = input()
  if x in A:
   ind = A.index(x)
   x = B[ind]
  s += x
 print(s)
 n = int(input())

Submission status: Wrong Answer

Solution code:

n = int(input())
while n != 0:
 A = []
 B = []
 for i in range(n):
  a, b = map(str, input().split())
  A.append(a)
  B.append(b)
 n = int(input())
 s = ''
 for i in range(n):
  x = str(input())
  if x in A:
   ind = A.index(x)
   x = B[ind]
  s += x
 print(s)
 n = int(input())

Submission status: Wrong Answer

Solution code:
def main():
    aaa = {}
    str = ""
    while 1:
        n = int(input())
        if not n:
            break
        for _ in range(n):
            INPUT = input().split()
            aaa[INPUT[0]] = INPUT[1]
        n = int(input())
        if not n:
            break
        for _ in range(n):
            a = input()
            str += aaa[a]if a in aaa else a
        print(str)
        aaa = {}
        str = ""
    return 0
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    print(''.join(outdata))

Submission status: Wrong Answer

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

    print(''.join(outdata))

Submission status: Wrong Answer

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()
		if c in convDict.keys():
			c = convDict[c];
		sys.stdout.write(c)
	print

Submission status: Wrong Answer

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()
        if s in table:
            rev += table[s]
        else:
            rev += s
    ans += rev + "\n"
print ans,

Submission status: Wrong Answer

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()
        if s in table:
            rev += table[s]
            del table[s]
        else:
            rev += s
    ans += rev + "\n"
print ans,

Submission status: Wrong Answer

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()
        if s in table:
            rev += table[s]
        else:
            rev += s
    ans += rev + "\n"
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

while 1:
    try:
        ans=[]
        dic={}
        n=int(input())
    
        for i in range(n):
            a,b = input().split()
            dic[a]=b
        
        m=int(input())
        for i in range(m):
            l=input()
            if l in dic:
                ans.append(dic[l])
            else:
                ans.append(l)
        print("".join(ans))        
        
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

while 1:
    try:
        ans=[]
        dic={}
        n=int(input())
    
        for i in range(n):
            a,b = input().split()
            dic[a]=b
        
        m=int(input())
        for i in range(m):
            l=input()
            if l in dic:
                ans.append(dic[l])
            else:
                ans.append(l)
        print("".join(ans)+"\n")        
        
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:

while 1:
    try:
        ans=[]
        dic={}
        n=int(input())
    
        for i in range(n):
            a,b = input().split()
            dic[a]=b
        
        m=int(input())
        for i in range(m):
            l=input()
            if l in dic:
                ans.append(dic[l])
            else:
                ans.append(l)
        print("".join(ans)+"\n")        
        
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

while 1:
    try:
        ans=[]
        dic={}
        n=int(input())
        if n==0:
            break
    
        for i in range(n):
            a,b = input().split()
            dic[a]=b
        
        m=int(input())
        for i in range(m):
            l=input()
            if l in dic:
                ans.append(dic[l])
            else:
                ans.append(l)
        print("".join(ans)+"\n")        
        
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
while 1:
    try:
        ans=[]
        dic={}
        n=int(input())
        if n==0:
            break
    
        for i in range(n):
            a,b = input().split()
            dic[a]=b
        
        m=int(input())
        for i in range(m):
            l=input()
            if l in dic:
                ans.append(dic[l])
            else:
                ans.append(l)
        print("".join(ans))        
        
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def registerDictionaryFromTheNumberOf(counts):
    dictionary = {}
    for i in range(counts):
        key, value = input().split(" ")
        dictionary[key] = value
    return dictionary
        
def readAndConvertCharacterAsManyAs(counts, dictionary):
    for i in range(counts):
        character = input()
        if character in dictionary:
            print("{0}".format(dictionary[character]),end="")
        else:
            print("{0}".format(character),end="")
    print("\n")
        
while True:
    dictionaryCounts = int(input())
    if dictionaryCounts == 0:
        break
    dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
    readAndConvertCharacterAsManyAs(int(input()), dictionary)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def registerDictionaryFromTheNumberOf(counts):
    dictionary = {}
    for i in range(counts):
        key, value = input().split(" ")
        dictionary[key] = value
    return dictionary
        
def readAndConvertCharacterAsManyAs(counts, dictionary):
    for i in range(counts):
        character = input()
        if character in dictionary:
            print("{0}".format(dictionary[character]),end="")
        else:
            print("{0}".format(character),end="")
    print("")
        
while True:
    dictionaryCounts = int(input())
    if dictionaryCounts == 0:
        break
    dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
    readAndConvertCharacterAsManyAs(int(input()), dictionary)

Submission status: Wrong Answer

Solution code:
def registerDictionaryFromTheNumberOf(counts):
    dictionary = {}
    for i in range(counts):
        key, value = input().split(" ")
        dictionary[key] = value
    return dictionary
         
def readAndConvertCharacterAsManyAs(counts, dictionary):
    for i in range(counts):
        character = input()
        if character in dictionary:
            print("{0}".format(dictionary[character]),end="")
        else:
            print("{0}".format(character),end="")
    print("")
         
while True:
    dictionaryCounts = int(input())
    if dictionaryCounts == 0:
        break
    dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
    readAndConvertCharacterAsManyAs(int(input()), dictionary)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    if n == 0:
        return False
    s = [input().split() for i in range(n)]
    m = int(input())
    t = [input() for i in range(m)]
    u = {v: v for v in t}

    for mae, ato in s:
        u[mae] = ato

    print(''.join([u[k] for k in t]))
    return True


while True:
    if main() is not True:
        break

Submission status: Wrong Answer

Solution code:
rows = int(input().strip())
_map = {x[0]: x[1] for x in (input().strip().split() for i in range(rows))}
rows = int(input().strip())
print(''.join([_map[x] if x in _map else x
               for x in (input().strip() for i in range(rows))]))

Submission status: Wrong Answer

Solution code:
rows = int(input().strip())
_map = {x[0]: x[1] for x in (input().strip().split() for i in range(rows))}
rows = int(input().strip())
print(''.join(_map[x] if x in _map else x
              for x in (input().strip() for i in range(rows))))

Submission status: Wrong Answer

Solution code:
rows = int(input().strip())
_map = {x[0]: x[1] for x in (input().strip().split() for _ in range(rows))}
rows = int(input().strip())
ans = ''
for _ in range(rows):
    c = input().strip()
    try:
        ans += _map[c]
    except KeyError:
        ans += c
print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    num = int(input())
    if(num == 0):
        break
    dic = {}
    for i in range(num):
        elem = input()
        dic[elem[0]] = elem[2]
    num2 = int(input())
    if(num2 == 0):
        break
    answer = ''
    for j in range(num2):
        elem2 = input()
        if(elem2 in dic):
            elem2 = dic[elem2]
        answer += elem2
    print(answer)

Submission status: Wrong Answer

Solution code:
while True:
    num = int(input())
    if(num == 0):
        break
    dic = {}
    for i in range(num):
        elem = input()
        dic[elem[0]] = elem[2]
    num2 = int(input())
    if(num2 == 0):
        break
    answer = ''
    for j in range(num2):
        elem2 = input()
        if(elem2 in dic):
            elem2 = dic[elem2]
        answer += elem2
    print(answer+'\n')

Submission status: Wrong Answer

Solution code:
while True:
    num = int(input())
    if(num == 0):
        break
    dic = {}
    for i in range(num):
        elem = input().split()
        dic[elem[0]] = elem[1]
    num2 = int(input())
    if(num2 == 0):
        break
    answer = ''
    for j in range(num2):
        elem2 = input()
        if(elem2 in dic):
            elem2 = dic[elem2]
        answer += elem2
    print(answer)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    trans = {}
    for _ in range(n):
        l = input().split()
        trans[l[0]] = l[1]
    m = int(input())
    data = ""
    for _ in range(m):
        l = input()
        data += trans[l] if l in trans else l
    print(data)

Submission status: Wrong Answer

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="")

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    conversion = {}
    for i in range(n):
        before, after = input().split()
        conversion[before] = after
    m = int(input())
    answer = []
    for i in range(m):
        char = input()
        if char in conversion:
            answer.append(conversion[char])
        else:
            answer.append(char)
    for w in answer:
        print(w, end="")
    print()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break
        else:
            cvs1, cvs2 = [""] * n, [""] * n   #conversion
            for x in range(n):
                cvs1[x], cvs2[x] = input().split()

            m = int(input())
            A = []
            for _ in range(m):
                A.append(input())

            s = ""
            for x in range(m):
                if A[x] in cvs1:
                    s += cvs2[cvs1.index(A[x])]
                else:
                    s += A[x]

            print(s)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break
        else:
            cvs1, cvs2 = [""] * n, [""] * n   #conversion
            for x in range(n):
                cvs1[x], cvs2[x] = input().split()

            m = int(input())
            A = []
            for _ in range(m):
                A.append(input())

            s = ""
            for x in range(m):
                if A[x] in cvs1:
                    s += cvs2[cvs1.index(A[x])]
                else:
                    s += A[x]

            print(s)
            print()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break
        else:
            cvs1, cvs2 = [""] * n, [""] * n   #conversion
            for x in range(n):
                cvs1[x], cvs2[x] = input().split()

            m = int(input())
            A = []
            for _ in range(m):
                A.append(input())

            s = ""
            for x in range(m):
                if A[x] in cvs1:
                    s += cvs2[cvs1.index(A[x])]
                else:
                    s += A[x]

            print(s)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break
        else:
            cvs1 = [0] * n   #conversion
            cvs2 = [0] * n
            for x in range(n):
                cvs1[x], cvs2[x] = input().split()

            m = int(input())
            m_list = []
            for _ in range(m):
                m_list.append(input())

            s = ""
            for x in range(m):
                if m_list[x] in cvs1:
                    s += cvs2[cvs1.index(m_list[x])]
                else:
                    s += m_list[x]

            print(s)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    x = {}
    for _ in range(n):
        a = input().split()
        x.update({a[0]: a[1]})
    m = int(input())
    y = []
    for _ in range(m):
        b = input()
        if b in x:
            y.append(x[b])
        else:
            y.append(b)
    for i in range(m):
        print(y[i], end="")
    print()

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    x = {}
    for _ in range(n):
        a = input().split()
        x.update({a[0]: a[1]})
    y = []
    for _ in range(int(input())):
        b = input()
        if b in x:
            y.append(x[b])
        else:
            y.append(b)
    print("".join(y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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