Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Chef has a positive integer N. He can apply any of the following operations as many times as he want in any order:

-  Add 1 to the number N.

-  Take some digit of N and replace it by any non-zero digit.

-  Add any non-zero leading digit to N.

Find the minimum number of operations that is needed for changing N to the lucky number.

-----Input-----
The first line contains a single positive integer T, the number of test cases. T test cases follow. The only line of each test case contains a positive integer N without leading zeros. 

-----Output-----
For each T test cases print one integer, the minimum number of operations that is needed for changing N to the lucky number.

-----Constraints-----

1 ≤ T ≤ 10

1 ≤ N < 10100000

-----Example-----
Input:
3
25
46
99

Output:
2
1
2

Source: codechef | Difficulty: MEDIUM
Tags: Constructive algorithms

Ad-hoc


Solutions:
for _ in range(int(input())):
	n = input().strip()
	cnt = 0
	for i in n:
		if i not in '47':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = input().strip()
	print(len(n) - (n.count('4') + n.count('7')))


t = int(input())
for i in range(t):
	s = str(input().strip())
	n = s.count('4') + s.count('7')
	n = len(s) - n
	print(n)


T = int(input())
for p in range(T):
	n = input().strip()
	counts = 0
	for i in n:
		if i != '4' and i != '7':
			counts = counts + 1
	print(counts)


from sys import stdin, stdout
t = int(stdin.readline().rstrip())
while t > 0:
	strg = list(stdin.readline().rstrip())
	i = 0
	count = 0
	while i < len(strg):
		if strg[i] != '4' and strg[i] != '7':
			count += 1
		i += 1
	print(count)
	t -= 1


for _ in range(int(input())):
	s = input().strip()
	k = 0
	for i in s:
		if i != '7' and i != '4':
			k += 1
	print(k)


t = int(input())
while t:
	t -= 1
	n = input().strip()
	x = n.count('4')
	y = n.count('7')
	print(len(n) - x - y)


t = int(input())
for i in range(t):
	n = list(input().strip())
	count = 0
	for ch in n:
		if ch != '4' and ch != '7':
			count += 1
	print(count)


for case in range(int(input())):
	number = input().strip()
	count = 0
	for i in number:
		if i != '4' and i != '7':
			count += 1
	print(count)


for _ in range(int(input())):
	n = input().strip()
	ans = 0
	for i in n:
		if i != '4' and i != '7':
			ans += 1
	print(str(ans))


def digits(n):
	count = 0
	for i in n:
		if i != '4' and i != '7':
			count += 1
	return count
t = int(input())
for _ in range(t):
	n = input().strip()
	print(digits(n))


for _ in range(int(input())):
	a = list(input().strip())
	fc = a.count('4')
	sc = a.count('7')
	if fc + sc == len(a):
		print(0)
	else:
		print(len(a) - fc - sc)


for _ in range(int(input())):
	n = input().strip()
	a = 0
	for i in n:
		if i != '4' and i != '7':
			a += 1
	print(a)


t = int(input())
for _ in range(t):
	a = str(input().strip())
	n = a.count('4') + a.count('7')
	n = len(a) - n
	print(n)


for _ in range(int(input())):
	st = input().strip()
	an = 0
	for ch in st:
		if ch == '4' or ch == '7':
			continue
		else:
			an += 1
	print(an)


for _ in range(int(input())):
	N = list(input().strip())
	a = N.count('4')
	b = N.count('7')
	print(len(N) - a - b)


tests = int(input())
for i in range(tests):
	num = input().strip()
	ans = 0
	for j in num:
		if j not in ['4', '7']:
			ans += 1
	print(ans)


T = int(input())
ans = []
for _ in range(T):
	N = input().strip()
	count = 0
	for i in N:
		if i != '4' and i != '7':
			count += 1
	ans.append(count)
for i in ans:
	print(i)


tests = int(input())
for test in range(tests):
	n = input().strip()
	length = len(n)
	steps = length - (n.count('4') + n.count('7'))
	print(steps)


for i in range(int(input())):
	s = str(input().strip())
	n1 = s.count('4')
	n2 = s.count('7')
	n = len(s) - n1 - n2
	print(n)


T = int(input())
for i in range(0, T):
	N = input().strip()
	cnt = 0
	for j in range(0, len(N)):
		if N[j] != '4' and N[j] != '7':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = input().strip()
	(seven, four) = (n.count('7'), n.count('4'))
	x = seven + four
	print(len(n) - x)


t = int(input())
for i in range(t):
	n = input().strip()
	ans = 0
	for i in n:
		if i != '4' and i != '7':
			ans += 1
	print(ans)


for i in range(int(input())):
	a = input().strip()
	A = str(a)
	B = A.count('4')
	C = A.count('7')
	print(len(A) - B - C)


for _ in range(int(input())):
	n = input().strip()
	ans = 0
	for ch in n:
		if ch != '4' and ch != '7':
			ans += 1
	print(ans)


t = int(input())
for tc in range(0, t):
	s = input().strip()
	c = 0
	for i in s:
		if i != '4' and i != '7':
			c += 1
	print(c)


for _ in range(int(input())):
	x = input().strip()
	f = x.count('4')
	s = x.count('7')
	l = len(x)
	print(l - f - s)


for t in range(int(input())):
	n = input().strip()
	c = n.count('4') + n.count('7')
	print(len(n) - c)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	s = input()
	ans = 0
	for i in s:
		if not (i == '4' or i == '7'):
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	n = input().strip()
	f = n.count('4')
	s = n.count('7')
	print(len(n) - (f + s))
	t = t - 1


for testcase in range(int(input())):
	value = input().strip()
	c = 0
	for i in value:
		if i != '4' and i != '7':
			c += 1
	print(c)


for t in range(int(input())):
	num = input().strip()
	count = 0
	for digit in num:
		if digit != '4' and digit != '7':
			count += 1
	print(count)


t = int(input())
while t:
	n = input().strip()
	c = 0
	for i in n:
		if i != '7' and i != '4':
			c += 1
	print(c)
	t -= 1


for i in range(int(input())):
	n = list(input().strip())
	c = n.count('4') + n.count('7')
	print(len(n) - c)


for _ in range(int(input())):
	N = input().strip()
	c = 0
	for i in N:
		if i != '4' and i != '7':
			c += 1
	print(c)


from sys import stdin, stdout
t = int(stdin.readline().rstrip())
while t > 0:
	strg = list(stdin.readline().rstrip())
	i = 0
	count = 0
	lst = ['4', '7']
	while i < len(strg):
		if strg[i] not in lst:
			count += 1
		i += 1
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	n = input().strip()
	cnt = 0
	for i in n:
		if i != '4' and i != '7':
			cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	n = input().strip()
	sev = n.count('7')
	four = n.count('4')
	print(len(n) - (sev + four))


for i in range(int(input())):
	count = 0
	num = input().strip()
	for i in num:
		if i != '4' and i != '7':
			count += 1
	print(count)


n = int(input())
for i in range(n):
	a = list(input().strip())
	c = 0
	for j in a:
		if j != '4' and j != '7':
			c += 1
	print(str(c))


for _ in range(int(input())):
	n = input().strip()
	count = 0
	for i in n:
		if i not in '74':
			count += 1
	print(count)


for _ in range(0, int(input())):
	n = input().strip()
	x = n.count('4')
	y = n.count('7')
	print(len(n) - x - y)


for _ in range(int(input())):
	s = input().strip()
	ans = 0
	for i in range(len(s)):
		if s[i] != '4' and s[i] != '7':
			ans += 1
	print(ans)


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 process_string(d):
	return 0 if d in '47' else 1

def solve(n):
	return sum([process_string(x) for x in n])

def do_codechef():
	for t in rii():
		n = si()
		print(solve(n))
do_codechef()
exit()


t = int(input())
for j in range(t):
	n = input().strip()
	c = 0
	for i in range(len(n)):
		if n[i] != '4' and n[i] != '7':
			c += 1
	print(c)


for i in range(int(input())):
	s = input().strip()
	c = 0
	for j in s:
		if j != '4' and j != '7':
			c += 1
	print(c)


for i in range(int(input())):
	num = input().strip()
	count = 0
	for i in num:
		if i == '7' or i == '4':
			continue
		else:
			count += 1
	print(count)