Solve the mystery

HINT : Digital Display
Input :
First line has an integer T.
Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero.

Output :
Print the output for each test case in new line.

Constraints :
1 ≤ T ≤ 1000
0 ≤ |N| ≤ 1000
|N| is number of digits.

Problem Setter : Vinay Kumar

SAMPLE INPUT
8
1234567
123456
1234
193
12
11
1
0

SAMPLE OUTPUT
30
27
16
13
7
4
2
6
from sys import stdin
tc = raw_input()
def sod(x):
	if x == 1:
		return 2
	elif x == 2 or x == 3 or x == 5 :
		return 5
	elif x == 4 :
		return 4
	elif x == 6 or x == 9:
		return 6
	elif x == 7:
		return 3
	elif x == 8:
		return 7
	else:
		return 6

for i in stdin:
	ans = 0
	for j in i:
		try:
			j = int(j)
			ans += sod(j)
		except ValueError:
			pass
	print ans