Kostya likes the number 4 much. Of course! This number has such a lot of properties, like:

- Four is the smallest composite number;
- It is also the smallest Smith number;
- The smallest non-cyclic group has four elements;
- Four is the maximal degree of the equation that can be solved in radicals;
- There is four-color theorem that states that any map can be colored in no more than four colors in such a way that no two adjacent regions are colored in the same color;
- Lagrange's four-square theorem states that every positive integer can be written as the sum of at most four square numbers;
- Four is the maximum number of dimensions of a real division algebra;
- In bases 6 and 12, 4 is a 1-automorphic number;
- And there are a lot more cool stuff about this number!

Impressed by the power of this number, Kostya has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the decimal representation. He is too busy now, so please help him.

-----Input-----
The first line of input consists of a single integer T, denoting the number of integers in Kostya's list.
Then, there are T lines, each of them contain a single integer from the list.

-----Output-----
Output T lines. Each of these lines should contain the number of occurences of the digit 4 in the respective integer from Kostya's list.

-----Constraints-----
- 1 ≤ T ≤ 105
- (Subtask 1): 0 ≤ Numbers from the list  ≤ 9 - 33 points.
- (Subtask 2): 0 ≤ Numbers from the list  ≤ 109 - 67 points.

-----Example-----
Input:
5
447474
228
6664
40
81

Output:
4
0
1
1
0

Difficulty: EASY
Tags: Mathematics

Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
for _ in range(int(input())):
	l = list(input())
	print(l.count('4'))


for i in range(int(input())):
	count = 0
	num = int(input())
	while num:
		if num % 10 == 4:
			count += 1
		num = int(num / 10)
	print(count)


n = int(input())
for i in range(n):
	count = 0
	for i in input():
		if i == '4':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	fours = 0
	num = int(input())
	fours = len([i for i in str(num) if int(i) == 4])
	print(fours)


t = int(input())
for i in range(t):
	sum = 0
	s = input()
	for i in range(len(s)):
		if s[i] == '4':
			sum = sum + 1
	print(sum)


t = int(input())
while t:
	t -= 1
	n = input()
	print(n.count('4'))


for t in range(int(input())):
	n = str(input())
	count = 0
	for i in n:
		if i != '4':
			pass
		else:
			count += 1
	print(count)


def four():
	n = input()
	count = 0
	for i in n:
		if int(i) == 0:
			continue
		elif int(i) == 4:
			count += 1
	print(count)
for _ in range(int(input())):
	four()


n = int(input())
for i in range(n):
	fours = 0
	num = int(input())
	while num:
		if num % 10 == 4:
			fours += 1
		num = int(num / 10)
	print(fours)


t = int(input())
i = 0
while i < t:
	i = i + 1
	n = int(input())
	sum = 0
	while n > 0:
		if n % 10 == 4:
			sum = sum + 1
			n = n // 10
		else:
			n = n // 10
	print(sum)


t = int(input())
for i in range(t):
	v = input()
	l = len(v)
	d = '4'
	c = 0
	for i in range(l):
		if v[i] == d:
			c += 1
	print(c)


n = int(input())
for i in range(n):
	s = 0
	a = input()
	for j in range(len(a)):
		if a[j] == '4':
			s += 1
	print(s)


n = int(input())
for i in range(n):
	a = int(input())
	c = 0
	while a:
		r = a % 10
		if r == 4:
			c = c + 1
		a = a // 10
	print(c)


n = int(input())
a = []
for i in range(0, n):
	no = int(input())
	a.append(no)
for i in range(0, n):
	c = 0
	while a[i] != 0:
		if a[i] % 10 == 4:
			c += 1
		a[i] = a[i] // 10
	print(c)


t = int(input())
for k in range(t):
	f4 = 0
	n = int(input())
	while n:
		if n % 10 == 4:
			f4 += 1
		n = int(n / 10)
	print(f4)


t = int(input())
for i in range(t):
	a = int(input())
	count = 0
	while a != 0:
		if a % 10 == 4:
			count += 1
		a = a // 10
	print(count)


s = int(input())
for i in range(s):
	n = input()
	c = 0
	for i in n:
		if i == '4':
			c += 1
	print(c)


t = eval(input())
for i in range(t):
	rem = []
	n = eval(input())
	while n > 0:
		rem.append(n % 10)
		n = n // 10
	print(rem.count(4))


from collections import Counter
for _ in range(int(input())):
	n = Counter(input().strip())
	print(n['4'])


T = int(input())
for tc in range(T):
	num = int(input())
	count = 0
	while num:
		rem = num % 10
		if rem == 4:
			count += 1
		num = num // 10
	print(count)


x = int(input())
for i in range(x):
	h = input()
	print(h.count('4'))


for k in range(int(input())):
	n = int(input())
	fours = 0
	a = list(str(n))
	for j in a:
		if j == '4':
			fours += 1
	print(fours)


n = int(input())
mylist = []
while n > 0:
	num = input()
	count = 0
	for i in num:
		if i == '4':
			count += 1
	mylist.append(count)
	n = n - 1
for i in mylist:
	print(i)


n = int(input())
for i in range(n):
	number = str(input())
	print(number.count('4'))


t = int(input())
for i in range(t):
	fours = 0
	num = input()
	for i in num:
		if i == '4':
			fours += 1
	print(fours)


n = int(input())
for i in range(n):
	s = input()
	c = s.count('4')
	print(c)


from collections import Counter
n = int(input())
for i in range(n):
	k = list(input())
	c = Counter(k)
	print(c['4'])


t = int(input())
for i in range(t):
	count = 0
	num = str(input())
	for x in num:
		if x == '4':
			count += 1
	print(count)


n = int(input())
while n > 0:
	s = input()
	print(len(s.split('4')) - 1)
	n = n - 1


a = str(4)
for _ in range(int(input())):
	n = str(input())
	count = 0
	for i in n:
		if i == a:
			count += 1
	print(count)


T = int(input())
for i in range(T):
	k = int(input())
	count = 0
	while k > 0:
		if k % 10 == 4:
			count += 1
		k //= 10
	print(count)


t = int(input())
for i in range(t):
	c = 0
	n = int(input())
	a = str(n)
	for i in a:
		if i == '4':
			c = c + 1
	print(c)


t = int(input())
for i in range(t):
	n = input()
	print(n.count('4'))


for i in range(int(input())):
	s = input()
	x = s.count('4')
	print(x)


try:
	t = int(input())
	while t != 0:
		t -= 1
		n = input()
		k = 0
		for j in range(0, len(n)):
			if n[j] == '4':
				k += 1
		print(k)
except:
	pass


arr = []
for a in range(int(input())):
	b = list(input())
	if '4' in b:
		arr.append(b.count('4'))
	else:
		arr.append(0)
print(*arr, sep='\n')