Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption.
The encrypted password is a string S consists of ASCII printable characters except space (ASCII 33 - 126, in decimal notation, the same below). Read here for more details: ASCII printable characters.
Each rule contains a pair of characters ci, pi, denoting that every character ci appears in the encrypted password should be replaced with pi. Notice that it is not allowed to do multiple replacements on a single position, see example case 1 for clarification.
After all the character replacements, the string is guaranteed to be a positive decimal number. The shortest notation of this number is the real password. To get the shortest notation, we should delete all the unnecessary leading and trailing zeros. If the number contains only non-zero fractional part, the integral part should be omitted (the shortest notation of "0.5" is ".5"). If the number contains zero fractional part, the decimal point should be omitted as well (the shortest notation of "5.00" is "5").
Please help Chef to find the real password.

-----Input-----
The first line of the input contains an interger T denoting the number of test cases.
The description of T test cases follows.
The first line of each test case contains a single interger N, denoting the number of rules.
Each of the next N lines contains two space-separated characters ci and pi,
denoting a rule.
The next line contains a string S, denoting the encrypted password.

-----Output-----
For each test case, output a single line containing the real password.

-----Constraints-----
- 1 ≤ T ≤ 1000
- 0 ≤ N ≤ 94
- All characters in S and ci may be any ASCII printable character except space. (ASCII 33 - 126)
- All ci in a single test case are distinct.
- pi is a digit ("0" - "9") or a decimal point "." (ASCII 46).
- The total length of S in a single input file will not exceed 106.

-----Example-----
Input:
4
2
5 3
3 1
5
0
01800.00
0
0.00100
3
x 0
d 3
# .
0xd21#dd098x

Output:
3
1800
.001
321.33098

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
for _ in range(int(input())):
	n = int(input())
	rule = []
	ci = ''
	pi = ''
	for _ in range(n):
		(c, p) = input().split()
		ci += c
		pi += p
	trans = str.maketrans(ci, pi)
	s = input()
	s = s.translate(trans)
	s = ''.join(s)
	dot = s.find('.')
	if dot != -1:
		s = s.strip('0').rstrip('.')
	else:
		s = s.lstrip('0')
	if s == '':
		print(0)
	else:
		print(s)


import sys
for t in range(int(input())):
	m = {}
	for i in range(int(input())):
		(ci, pi) = input().split()
		m[ci] = pi
	s = input()
	ans = ''
	for i in range(len(s)):
		try:
			ans += m[s[i]]
		except:
			ans += s[i]
	dots = ans.count('.')
	if dots > 1:
		exit(1)
	if dots == 0:
		ans = ans.lstrip('0')
		if len(ans) == 0:
			print('0')
		else:
			print(ans)
	else:
		ans = ans.strip('0')
		size = len(ans)
		if size == 1:
			print('0')
			continue
		if ans[size - 1] == '.':
			ans = ans[:size - 1]
		print(ans)


a = int(input())
for _ in range(a):
	table = {}
	res = 0
	aa = int(input())
	for i in range(aa):
		bb = list(input().split())
		table[bb[0]] = bb[1]
	cc = list(input())
	for i in range(len(cc)):
		if cc[i] in table:
			cc[i] = table[cc[i]]
		if cc[i] == '.':
			res = 1
	i = 0
	while cc[i] == '0' and cc[i] != '.':
		i += 1
		if i == len(cc):
			print('0', end=' ')
			break
	j = len(cc) - 1
	if res == 1:
		while cc[j] == '0':
			j -= 1
		if cc[j] == '.':
			j -= 1
	if i == j + 1 and res == 1:
		print('0')
		continue
	while i <= j:
		print(cc[i], end='')
		i += 1
	print('\n', end='')


for test in range(int(input())):
	N = int(input())
	rules = {}
	for i in range(N):
		cp = input().split()
		rules[cp[0]] = cp[1]
	encryption = input()
	passwd = ''
	for i in encryption:
		if rules.get(i):
			passwd += rules[i]
		else:
			passwd += i
	passwd = passwd.lstrip('0')
	if passwd.find('.') != -1:
		passwd = passwd.rstrip('0')
	try:
		if passwd[-1] == '.':
			passwd = passwd[:-1]
			if passwd == '':
				print(0)
			else:
				print(passwd)
		else:
			print(passwd)
	except:
		print(0)


from decimal import Decimal
T = int(input())
for _ in range(T):
	N = int(input())
	data = dict()
	for __ in range(N):
		(ci, pi) = input().split()
		data[ci] = pi
	S = list(input())
	for i in range(len(S)):
		if S[i] in data.keys():
			S[i] = data[S[i]]
	S = ''.join(S)
	if '.' in S:
		S = S.strip('0').rstrip('.')
	else:
		S = S.lstrip('0')
	print(S or '0')


t = int(input())
for ttt in range(t):
	n = int(input())
	rules = {}
	for i in range(n):
		q = input().split(' ')
		a = q[0]
		b = q[1]
		rules[a] = b
	s0 = input()
	s1 = ''
	for i in s0:
		if i in rules.keys():
			s1 += rules[i]
		else:
			s1 += i
	if all((x == '0' or x == '.' for x in s1)):
		print('0')
	else:
		czy = '.' in s1
		p = 0
		while s1[p] == '0':
			p += 1
		k = len(s1) - 1
		while czy and s1[k] == '0':
			k -= 1
		if s1[k] == '.':
			k -= 1
		print(s1[p:k + 1])


for _ in range(int(input())):
	d = {}
	for __ in range(int(input())):
		(c, p) = map(str, input().split())
		d[c] = p
	s = input()
	k = ''
	for i in range(0, len(s)):
		if s[i] in d.keys():
			k = k + d[s[i]]
		else:
			k = k + s[i]
	if '.' in k:
		k = k.strip('0').rstrip('.')
	else:
		k = k.lstrip('0')
	print(k or '0')


for __ in range(int(input())):
	rules = dict()
	for _ in range(int(input())):
		(c, p) = (x for x in input().split())
		rules[c] = p
	orig_s = input()
	new_s = ''
	for i in orig_s:
		new_s += rules.get(i, i)
	new_s = new_s.lstrip('0')
	if '.' in new_s:
		new_s = new_s.rstrip('0').rstrip('.')
	print(new_s if new_s != '' else '0')


def removeleading(s):
	c = 0
	for i in range(len(s)):
		if s[i] == '0':
			c += 1
		else:
			break
	s = s[c:]
	return s

def removetrailing(s):
	c = 0
	i = len(s) - 1
	while i >= 0:
		if s[i] == '0':
			c += 1
		else:
			break
		i -= 1
	if c > 0:
		s = s[:-c]
	return s

def removepoint(s):
	if s[len(s) - 1] == '.':
		s = s[:-1]
	return s
t = int(input())
for i in range(t):
	n = int(input())
	if n > 0:
		asc = [' '] * 150
		for i in range(n):
			(a, b) = [str(i) for i in input().split()]
			a = str(a)
			asc[ord(a)] = b
		inp = list(input())
		for i in range(len(inp)):
			if not asc[ord(inp[i])] == ' ':
				x = asc[ord(inp[i])]
				x = str(x)
				inp[i] = x
		inp = ''.join(inp)
		if len(inp) == 1:
			print(inp)
		else:
			inp = removeleading(inp)
			if '.' in inp:
				inp = removetrailing(inp)
			if len(inp) > 1:
				inp = removepoint(inp)
			if inp == '.' or inp == '':
				print('0')
			else:
				print(inp)
		del asc
	else:
		inp = input()
		if len(inp) == 1:
			print(inp)
		else:
			inp = removeleading(inp)
			if '.' in inp:
				inp = removetrailing(inp)
			if len(inp) > 1:
				inp = removepoint(inp)
			if inp == '.' or inp == '':
				print('0')
			else:
				print(inp)


def main():
	length = int(input())
	for test_case in range(length):
		rules = str.maketrans(parse_rules(int(input())))
		password = input().translate(rules)
		(before, decimal, after) = password.partition('.')
		trimmed = before.lstrip('0') + (decimal + after).rstrip('0.')
		print(trimmed or '0')

def parse_rules(rule_count):
	rules = dict()
	for rule in range(rule_count):
		(original, replacement) = input().split()
		rules[original] = replacement
	return rules
main()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	From = ''
	To = ''
	for _ in range(N):
		(Ci, Pi) = sys.stdin.readline().strip().split()
		From += Ci
		To += Pi
	S = sys.stdin.readline().strip()
	S = S.translate(str.maketrans(From, To))
	if '.' not in S:
		S += '.'
	S = S.strip('0')
	if S.endswith('.'):
		S = S.strip('.')
	if not S:
		S = '0'
	print(S)


t = int(input())
for tti in range(t):
	n = int(input())
	X = {}
	for i in range(n):
		(a, b) = list(input().split(' '))
		X[a] = b
	w = input()
	x = ''
	for i in range(len(w)):
		if w[i] in X.keys():
			x += X[w[i]]
		else:
			x += w[i]
	if len(x.split('.')) == 1:
		ii = 0
		while ii < len(x) and x[ii] == '0':
			ii += 1
		if x[ii:] != '':
			print(x[ii:])
		else:
			print(0)
	else:
		ii = 0
		while ii < len(x) and x[ii] == '0':
			ii += 1
		jj = len(x) - 1
		while jj > 0 and x[jj] == '0':
			jj -= 1
		if x[jj] == '.':
			jj -= 1
		if x[ii:jj + 1] != '':
			print(x[ii:jj + 1])
		else:
			print(0)


import sys
ssr = sys.stdin.readline
ssw = sys.stdout.write
for i in range(int(ssr())):
	rules = dict()
	for j in range(int(ssr())):
		(old, new) = ssr().strip().split()
		rules[old] = new
	rules = str.maketrans(rules)
	answer = ssr().strip().translate(rules)
	answer = answer.lstrip('0')
	if '.' in answer:
		answer = answer.rstrip('0').rstrip('.')
	ssw(answer or '0')
	ssw('\n')


try:
	from debug import debug, timer
except ImportError:
	pass
from sys import stdin
input = stdin.readline

def rii():
	return range(int(input().strip()))

def ii():
	return int(input().strip())

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())

def getvals():
	while True:
		yield from input().split()

def tri(n):
	return n * (n + 1) // 2

def smallest_first(m, n):
	return (min(m, n), max(m, n))

def solve(*args):
	(n, d, s) = args
	outp = ''.join([d[x] if x in d else x for x in s])
	outp = outp.lstrip('0')
	if '.' in outp:
		outp = outp.rstrip('0')
		outp = outp.rstrip('.')
	if outp == '':
		return 0
	return outp

def do_codechef():
	for t in rii():
		n = ii()
		d = {a: b for (a, b) in (si().split(' ') for _ in range(n))}
		s = si()
		print(solve(n, d, s))
do_codechef()
exit()


def find_password():
	password = ''
	for char in S:
		if char in C:
			i = C.index(char)
			password += P[i]
		else:
			password += char
	password = password.lstrip('0')
	if '.' in password:
		password = password.rstrip('0')
		password = password.rstrip('.')
	if not password:
		password = '0'
	print(password)
T = int(input())
for _ in range(T):
	N = int(input())
	C = []
	P = []
	for _ in range(N):
		(c, p) = input().split()
		C.append(c)
		P.append(p)
	S = input()
	find_password()


for _ in range(int(input())):
	n = int(input())
	rep = {}
	for i in range(n):
		(c, p) = input().split()
		rep[c] = p
	s = input()
	new = ''
	bl = False
	for i in s:
		if i in rep:
			new += rep[i]
		else:
			new += i
		if new[-1] == '.':
			bl = True
	start = -1
	for i in new:
		if i == '0':
			start += 1
		else:
			break
	if start > -1:
		new = new[start + 1:]
	end = len(new)
	if bl:
		for i in new[::-1]:
			if i == '0':
				end -= 1
			elif i == '.':
				end -= 1
				break
			else:
				break
	if new[:end] == '':
		print(0)
	else:
		print(new[:end])


def releze(s):
	for i in range(len(s)):
		if s[i] != '0':
			break
	s = s[i:]
	return s

def retrze(s):
	for i in range(len(s) - 1, -1, -1):
		if s[i] != '0':
			break
	s = s[:i + 1]
	return s
t = int(input())
for a0 in range(t):
	n = int(input())
	a1 = []
	a2 = []
	for a4 in range(n):
		t = input().strip().split(' ')
		a1.append(t[0])
		a2.append(t[1])
	s = input()
	ds = {}
	sa = []
	fsa = []
	for i in range(len(s)):
		sa.append(s[i])
		fsa.append(' ')
		if s[i] in ds:
			ds[s[i]].append(i)
		else:
			ds[s[i]] = [i]
	for i in range(len(a1)):
		if a1[i] in ds:
			for j in ds[a1[i]]:
				fsa[j] = a2[i]
			ds.pop(a1[i], None)
	for i in ds:
		for j in ds[i]:
			fsa[j] = i
	s = releze(''.join(fsa))
	if '.' in s:
		s = retrze(s)
	if s[-1] == '.':
		s = s[:-1]
	if len(s) == 0:
		print('0')
	else:
		print(s)


__author__ = 'zumzoom'
import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	rules = dict()
	for __ in range(n):
		(c, x) = sys.stdin.readline().split()
		rules[c] = x
	s = sys.stdin.readline()[:-1]
	news = ''
	for c in s:
		if c in rules.keys():
			news += rules[c]
		else:
			news += c
	news += 'p'
	for i in range(len(news)):
		if news[i] != '0':
			news = news[i:]
			break
	news = news[:-1]
	if '.' in news and news[-1] == '0':
		for i in range(2, len(news) + 1):
			if news[-i] != '0':
				news = news[:-i + 1]
				break
	if len(news) > 0 and news[-1] == '.':
		news = news[:-1]
	if news == '':
		news = '0'
	print(news)


def work():
	n = int(input())
	c = ''
	p = ''
	for i in range(n):
		rule = input().strip().split()
		c += rule[0]
		p += rule[1]
	trans = str.maketrans(c, p)
	encrypted = input().strip()
	encrypted = encrypted.translate(trans)
	ans = ''
	for i in range(len(encrypted)):
		if encrypted[i] != '0':
			ans = encrypted[i:]
			break
	has_point = False
	for ch in ans:
		if ch == '.':
			has_point = True
			break
	if has_point:
		end = len(ans)
		while ans[end - 1] == '0':
			end -= 1
		if ans[end - 1] == '.':
			end -= 1
		ans = ans[:end]
	if len(ans) == 0:
		ans = '0'
	print(ans)

def main():
	cases = int(input().strip())
	for i in range(cases):
		work()
main()