mystery-7-1

Solve The Mystery

Input:
First line contains T - number of test cases.
Following T lines each contains a string of characters in the range [a-z] only  

Output:
Print a numeric string for each test case.  

Constraints:
1 ≤ T ≤ 100
1 ≤ Length of String ≤ 100  

SAMPLE INPUT
10
key
to
control
nine
tails
is
in
your
hand
phone

SAMPLE OUTPUT
539
86
2668765
6463
82457
47
46
9687
4263
74663

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
from sys import stdin
for i in range(int(stdin.readline())):
	st=''
	for j in stdin.readline():
		if j in 'abc':
			st+='2'
		elif j in 'def':
			st+='3'
		elif j in 'ghi':
			st+='4'
		elif j in 'jkl':
			st+='5'
		elif j in 'mno':
			st+='6'
		elif j in 'pqrs':
			st+='7'
		elif j in 'tuv':
			st+='8'
		elif j in 'wxyz':
			st+='9'
	print(st)



'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
n=int(input())

while n!=0:
	s=str(input())
	l=len(s)
	for i in range(0,l):
		if(s[i] == 'a' or s[i] == 'A' or s[i] == 'B' or s[i] == 'b' or s[i] == 'C' or s[i] == 'c'):
			sys.stdout.write('2'),
		elif(s[i] == 'd' or s[i] == 'D' or s[i] == 'E' or s[i] == 'e' or s[i] == 'F' or s[i] == 'f'):
			sys.stdout.write('3'),
		elif s[i] == 'G' or s[i] == 'g' or s[i] == 'H' or s[i] == 'h' or s[i] == 'I' or s[i] == 'i':
			sys.stdout.write('4'),
		elif s[i] ==  'J' or s[i] ==  'j' or s[i] ==  'K' or s[i] ==  'k' or s[i] ==  'L' or s[i] ==  'l':
			sys.stdout.write('5'),
		elif s[i] ==  'M' or s[i] ==  'm' or s[i] ==  'N' or s[i] ==  'n' or s[i] ==  'O' or s[i] ==  'o':
			sys.stdout.write('6'),
		elif s[i] ==  'P' or s[i] ==  'p' or s[i] ==  'Q' or s[i] ==  'q' or s[i] ==  'R' or s[i] ==  'r' or s[i] ==  'S' or s[i] ==  's':
			sys.stdout.write('7'),
		elif s[i] ==  'T' or s[i] ==  't' or s[i] ==  'U' or s[i] ==  'u' or s[i] ==  'V' or s[i] ==  'v':
			sys.stdout.write('8'),
		else:
			sys.stdout.write('9'),
	print("")		
	n=n-1


import string
def cal(p):
	a=['a','b','c']
	b=['d','e','f']
	c=['g','h','i']
	d=['j','k','l']
	e=['m','n','o']
	f=['p','q','r','s']
	g=['t','u','v']
	h=['w','x','y','z']
	for i in range(0,len(p)):
		if p[i] in a:
			p=p.replace(p[i],'2')
		if p[i] in b:
			p=p.replace(p[i],'3')
		if p[i] in c:
			p=p.replace(p[i],'4')
		if p[i] in d:
			p=p.replace(p[i],'5')
		if p[i] in e:
			p=p.replace(p[i],'6')
		if p[i] in f:
			p=p.replace(p[i],'7')
		if p[i] in g:
			p=p.replace(p[i],'8')
		if p[i] in h:
			p=p.replace(p[i],'9')
	print(p)    
k=eval(input())

for i in range(0,k):
	p=input()
	b=cal(p)


i=eval(input())
#print i
for _ in range(0,i):
	case=(input())
	temp=''
	for x in range(0, len(case)):
		if case[x]>='j' and case[x]<='l':
			temp+='5'
		elif case[x]>='d' and case[x]<='f':
			temp+='3'
		elif case[x]>='t' and case[x]<='v':
			temp+='8'
		elif case[x]>='m' and case[x]<='o':
			temp+='6'
		elif case[x]>='a' and case[x]<='c':
			temp+='2'
		elif case[x]>='g' and case[x]<='i':
			temp+='4'
		elif case[x]>='p' and case[x]<='s':
			temp+='7'
		elif case[x]>='w' and case[x]<='z': 
			temp+='9'
	print(temp)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def print_number(input_string):
	output = ''
	t9_dict = {}
	t9_dict['a'] = t9_dict['b'] = t9_dict['c'] = 2
	t9_dict['d'] = t9_dict['e'] = t9_dict['f'] = 3
	t9_dict['g'] = t9_dict['h'] = t9_dict['i'] = 4
	t9_dict['j'] = t9_dict['k'] = t9_dict['l'] = 5
	t9_dict['m'] = t9_dict['n'] = t9_dict['o'] = 6
	t9_dict['p'] = t9_dict['q'] = t9_dict['r'] = t9_dict['s'] = 7
	t9_dict['t'] = t9_dict['u'] = t9_dict['v'] = 8
	t9_dict['w'] = t9_dict['x'] = t9_dict['y'] = t9_dict['z'] = 9

	for char in input_string:
		output = output + str(t9_dict[char])
	print(output)



if __name__ == '__main__':
	cases = int(input().strip())
	start = 1
	while start <= cases:
		input_string = input().strip()
		print_number(input_string)
		start = start + 1


t=int(input())
for W in range(t):
	s=input()
	A=list(s)
	i=0
	while i<len(A):
	   if A[i]=='a' or A[i]=='b' or A[i]=='c':
		   A[i]='2'
	   elif A[i]=='d' or A[i]=='e' or A[i]=='f':
		   A[i]='3'
		   
	   elif A[i]=='g' or A[i]=='h' or A[i]=='i':
		   A[i]='4'
	   elif A[i]=='j' or A[i]=='k' or A[i]=='l':
		   A[i]='5'
	   elif A[i]=='m' or A[i]=='n' or A[i]=='o':
		   A[i]='6'
	   elif A[i]=='p' or A[i]=='q' or A[i]=='r' or A[i]=='s':
		   A[i]='7'
	   elif A[i]=='t' or A[i]=='u' or A[i]=='v':
		   A[i]='8'
	   elif A[i]=='x' or A[i]=='y' or A[i]=='z'  or A[i]=='w':
		   A[i]='9'
	   i=i+1    
	z=''.join(A)
	print(z)


l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
asc=[2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9]
t=eval(input())
for x in range(0,t):
	st=input()
	ans=''
	ind=0
	lst=list(st)
	for j in range(0,len(lst)):
		ind=l.index(lst[j])
		ans=ans+str(asc[ind])
	print(ans)


from sys import stdin
for i in range(int(stdin.readline())):
	st=''
	for j in stdin.readline():
		if j in 'abc':
			st+='2'
		elif j in 'def':
			st+='3'
		elif j in 'ghi':
			st+='4'
		elif j in 'jkl':
			st+='5'
		elif j in 'mno':
			st+='6'
		elif j in 'pqrs':
			st+='7'
		elif j in 'tuv':
			st+='8'
		elif j in 'wxyz':
			st+='9'
	print(st)


t=int(input())
for W in range(t):
	s=input()
	A=list(s)
	i=0
	while i<len(A):
	   if A[i]=='a' or A[i]=='b' or A[i]=='c':
		   A[i]='2'
	   elif A[i]=='d' or A[i]=='e' or A[i]=='f':
		   A[i]='3'
		   
	   elif A[i]=='g' or A[i]=='h' or A[i]=='i':
		   A[i]='4'
	   elif A[i]=='j' or A[i]=='k' or A[i]=='l':
		   A[i]='5'
	   elif A[i]=='m' or A[i]=='n' or A[i]=='o':
		   A[i]='6'
	   elif A[i]=='p' or A[i]=='q' or A[i]=='r' or A[i]=='s':
		   A[i]='7'
	   elif A[i]=='t' or A[i]=='u' or A[i]=='v':
		   A[i]='8'
	   elif A[i]=='x' or A[i]=='y' or A[i]=='z'  or A[i]=='w':
		   A[i]='9'
	   i=i+1    
	z=''.join(A)
	print(z)