Read problems statements in Mandarin Chinese here 

------ Problem Statement ------ 

Maxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city.
 
If you remember, lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky, 5, 17, 467 — aren't.
 
Now Maxim is interested in the next information: what is the number of the integer positive dividers of number n, which are overlucky.
 
We call number overlucky if it is possible to remove some, but not all, digits and during bonding the remaining digits we will receive a lucky number. For example, number 72344 — overlucky, because it is possible to remove digits 2 and 3, and get number 744, which is lucky. Number 223 isn't overlucky. 

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Single line of each test case contains an integer n. 

------ Output ------ 

For each test case on different lines print the answer to the problem.
------ Constraints ------ 

$1 ≤ T ≤ 10$
$1 ≤ n ≤ 10^{9}$
 
----- Sample Input 1 ------ 
10
1
2
3
4
5
6
7
8
9
10
----- Sample Output 1 ------ 
0
0
0
1
0
0
1
1
0
0

Source: codechef | Difficulty: MEDIUM
Tags: Number theory


Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(1, int(n ** 0.5) + 1):
		if n % j == 0:
			s1 = ''
			s2 = ''
			s1 += str(j)
			s2 += str(n // j)
			if s1.find('4') != -1 or s1.find('7') != -1:
				l.append(s1)
			if s2.find('4') != -1 or s2.find('7') != -1:
				l.append(s2)
	ans = set(l)
	print(len(ans))


def is_overlucky(num):
	num = str(num)
	for i in num:
		if i in ['4', '7']:
			return True
	return False
testcase = int(input())
for z in range(testcase):
	num = int(input())
	count = 0
	for i in range(1, int(num ** 0.5) + 1):
		if num % i == 0:
			if is_overlucky(i):
				count = count + 1
			complement = num / i
			if complement != i:
				if is_overlucky(complement):
					count = count + 1
	print(count)


def over_div(x):
	c = 0
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			t_1 = x / i
			if t_1 != i:
				if overlucky(t_1) == True:
					c += 1
			if overlucky(i) == True:
				c += 1
	return c

def overlucky(a):
	a = str(a)
	if a.count('4') >= 1 or a.count('7') >= 1:
		return True
	return False
for _ in range(int(input())):
	n = int(input())
	print(over_div(n))


import math

def solve(n):
	s = '7'
	f = '4'
	res = 0
	for i in range(1, math.ceil(n ** 0.5) + 1):
		if n % i == 0:
			if s in str(i) or f in str(i):
				res += 1
			y = n // i
			if i != y:
				if s in str(y) or f in str(y):
					res += 1
	return res
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


from math import sqrt

def count(N):
	count = 0
	for i in range(1, int(sqrt(N)) + 1):
		if N % i == 0:
			a = N // i
			if a == i:
				if '4' in str(a) or '7' in str(a):
					count += 1
			else:
				if '4' in str(a) or '7' in str(a):
					count += 1
				if '4' in str(i) or '7' in str(i):
					count += 1
	return count
T = int(input())
for j in range(T):
	N = int(input())
	print(count(N))


def isOverlucky(n):
	for c in str(n):
		if c == '4' or c == '7':
			return True
	return False

def gindy(n):
	div = set()
	L = int(n ** 0.5) + 2
	for i in range(1, L):
		if n % i == 0:
			if isOverlucky(i):
				div.add(i)
			if isOverlucky(n // i):
				div.add(n // i)
	return len(div)
TC = int(input())
for _ in range(TC):
	n = int(input())
	print(gindy(n))


import math

def getdiv(N, dv):
	for i in range(1, int(math.sqrt(N)) + 1):
		if N % i == 0:
			dv.append(i)
			if int(N / i) != i:
				dv.append(int(N / i))

def checkoverlucky(num):
	seven = 0
	four = 0
	other = 0
	num = str(num)
	for i in num:
		if i == '4':
			four = 1
		elif i == '7':
			seven = 1
		else:
			other = 1
	if four == 1 or seven == 1:
		return 1
	else:
		return 0
T = int(input())
for t in range(T):
	N = int(input())
	dv = []
	getdiv(N, dv)
	c = 0
	for num in dv:
		if checkoverlucky(num) == 1:
			c += 1
	print(c)


from functools import reduce

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
for _ in range(int(input())):
	print(len([i for i in [str(i) for i in factors(int(input()))] if '4' in i or '7' in i]))


for u in range(int(input())):
	n = int(input())
	c = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			x = i
			y = n // i
			if x == y:
				if '4' in str(x) or '7' in str(x):
					c += 1
			else:
				if '4' in str(x) or '7' in str(x):
					c += 1
				if '4' in str(y) or '7' in str(y):
					c += 1
	print(c)


from math import *
for j in range(int(input())):
	c = 0
	n = int(input())
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				a = str(i)
				if '4' in a or '7' in a:
					c += 1
			else:
				b = str(n // i)
				if '4' in b or '7' in b:
					c += 1
				d = str(i)
				if '4' in d or '7' in d:
					c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	list1 = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			str1 = ''
			str2 = ''
			str1 += str(i)
			str2 += str(n // i)
			if str1.find('4') != -1 or str1.find('7') != -1:
				list1.append(str1)
			if str2.find('4') != -1 or str2.find('7') != -1:
				list1.append(str2)
	set1 = set(list1)
	print(len(set1))


for t in range(int(input())):
	n = int(input())
	n2 = int(n ** 0.5)
	ct = 0
	for num in range(1, n2 + 1):
		if n % num == 0 and ('4' in str(num) or '7' in str(num)):
			ct += 1
		if n % num == 0:
			tmp = str(n // num)
			if ('4' in tmp or '7' in tmp) and tmp != str(num):
				ct += 1
	print(ct)


from math import sqrt

def count(N):
	count = 0
	for i in range(1, int(sqrt(N)) + 1):
		if N % i == 0:
			a = N // i
			if a == i:
				if '4' in str(a) or '7' in str(a):
					count += 1
			else:
				if '4' in str(a) or '7' in str(a):
					count += 1
				if '4' in str(i) or '7' in str(i):
					count += 1
	return count
test = int(input())
for _ in range(test):
	n = int(input())
	print(count(n))


from math import sqrt
value = []
for _ in range(int(input())):
	n = int(input())
	count = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			res = n // i
			if res != i:
				if '7' in str(res) or '4' in str(res):
					count += 1
			if '7' in str(i) or '4' in str(i):
				count += 1
	value.append(count)
for i in range(len(value)):
	print(value[i])


import math
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if '4' in str(i) or '7' in str(i):
				ans += 1
			if i != n / i:
				if '4' in str(n / i) or '7' in str(n / i):
					ans += 1
	print(ans)


from math import *
t = int(input())
for k in range(t):
	count = 0
	i = int(input())
	p = []
	for j in range(1, int(sqrt(i) + 1)):
		if i % j == 0:
			p.append(str(j))
			if i / j != j:
				p.append(str(i // j))
	for i in p:
		if '4' in i or '7' in i:
			count += 1
	print(count)


from sys import stdin, stdout

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
t = int(sin())
for _ in range(t):
	n = int(sin())
	lim = int(n ** 0.5)
	ans = 1 if str(n).find('4') != -1 or str(n).find('7') != -1 else 0
	for i in range(2, lim + 1):
		if n % i == 0:
			if str(i).find('4') != -1 or str(i).find('7') != -1:
				ans += 1
			j = n // i
			if j != i and (str(j).find('4') != -1 or str(j).find('7') != -1):
				ans += 1
	print(ans)


import math

def find(s):
	return '7' in s or '4' in s
for _ in range(int(input())):
	n = int(input())
	count = 0
	p = int(math.sqrt(n))
	for i in range(1, p + 1):
		if n % i == 0:
			c = n // i
			if c != i:
				if find(str(c)):
					count += 1
			if find(str(i)):
				count += 1
	print(count)


import math

def Divisiors(n):
	ans = 0
	v = int(math.sqrt(n))
	for i in range(1, v + 1):
		k = n // i
		if n % i == 0:
			if '4' in str(i) or '7' in str(i):
				ans += 1
			if k != i:
				if '4' in str(k) or '7' in str(k):
					ans += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	print(Divisiors(n))


case = int(input())
for i in range(case):
	n = int(input())
	count = 0
	j = 1
	while j * j <= n:
		if n % j == 0:
			if '4' in str(j) or '7' in str(j):
				count += 1
			if ('4' in str(n // j) or '7' in str(n // j)) and n != j * j:
				count += 1
		j += 1
	print(count)


T = int(input())
for i in range(T):
	n = int(input())
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			s1 = ''
			s2 = ''
			s1 += str(i)
			s2 += str(n // i)
			if s1.find('4') != -1 or s1.find('7') != -1:
				l.append(s1)
			if s2.find('4') != -1 or s2.find('7') != -1:
				l.append(s2)
	op = set(l)
	print(len(op))


def fun(a):
	arr = []
	for i in range(1, int(a ** (1 / 2)) + 1):
		if a % i == 0:
			arr.append(str(i))
			arr.append(str(int(a / i)))
	return arr
t = int(input())
for isd in range(t):
	n = int(input())
	a = fun(n)
	k = 0
	for i in set(a):
		if '4' in i or '7' in i:
			k += 1
	print(k)


def divisors(n):
	r = []
	a = int(n ** 0.5 + 1)
	for i in range(1, a):
		if n % i == 0:
			r.append(i)
			if n // i != i:
				r.append(n // i)
	return r

def lucky(n):
	for i in n:
		if i != '4' or i != '7':
			return False
	return True

def overlucky(n):
	s = ''
	for i in n:
		if i == '4' or i == '7':
			s += i
	if s == '':
		return False
	else:
		return True
T = int(input())
for i in range(T):
	N = int(input())
	count = 0
	for i in divisors(N):
		if lucky(str(i)):
			count += 1
		elif overlucky(str(i)):
			count += 1
	print(count)


from math import sqrt

def find_all_factors(n):
	count = 0
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			a = str(n // i)
			b = str(i)
			if a != b:
				if '4' in a or '7' in a:
					count += 1
				if '4' in b or '7' in b:
					count += 1
			elif '4' in a or '7' in a:
				count += 1
	return count
t = int(input())
for test in range(t):
	n = int(input())
	factors = find_all_factors(n)
	print(factors)


import math
n = int(input())
for i in range(n):
	inp = int(input())
	count = 0
	for j in range(1, math.floor(inp ** 0.5) + 1):
		if inp % j == 0:
			for a in str(inp // j):
				if a == '4' or a == '7':
					count += 1
					break
			if inp != j * j:
				for a in str(j):
					if a == '4' or a == '7':
						count += 1
						break
	print(count)


import math

def Check(n):
	while n != 0:
		if n % 10 == 7 or n % 10 == 4:
			return True
		n //= 10
	return False
t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if Check(i):
				count += 1
			if Check(n // i):
				count += 1
	print(count)


def lucky_dividers(n):
	count = 0
	for i in range(1, int(n ** 0.5) + 1):
		(a, b) = (i, n // i)
		for val in [a, b]:
			if n % val == 0 and len(set(str(val)) & set('47')) > 0:
				count += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	print(lucky_dividers(n))


from math import sqrt as S

def cont(n):
	cnt = 0
	if '4' in str(n) or '7' in str(n):
		cnt += 1
	for i in range(2, int(S(n)) + 1):
		if n % i == 0:
			if i != n // i:
				if '4' in str(i) or '7' in str(i):
					cnt += 1
				other = n // i
				if '4' in str(other) or '7' in str(other):
					cnt += 1
			elif '4' in str(i) or '7' in str(i):
				cnt += 1
	return cnt
for _ in range(int(input())):
	n = int(input())
	print(cont(n))


import math

def isvalid(x):
	if '4' in set(str(x)) or '7' in set(str(x)):
		return 1
	return 0
T = int(input())
for t in range(T):
	x = int(input())
	res = 0
	for i in range(1, int(math.sqrt(x)) + 1):
		if x % i == 0 and isvalid(i):
			res += 1
		if x % i == 0 and isvalid(x // i) and (i * i != x):
			res += 1
	print(res)


def check(x):
	a = 0
	while x:
		if x % 10 == 4 or x % 10 == 7:
			a += 1
			break
		x = x // 10
	if a > 0:
		return 1
	else:
		return 0
for i in range(int(input())):
	n = int(input())
	count = check(n)
	s = int(n ** (1 / 2))
	for j in range(2, s + 1):
		if n % j == 0:
			count += check(j)
			count += check(n / j)
	if n / s == s:
		count -= check(s)
	print(count)


def count_overlucky_numbers(n):
	num_overlucky_numbers = 0
	if contains_4_or_7(n):
		num_overlucky_numbers += 1
	i = 2
	while i * i <= n:
		if n % i == 0:
			if contains_4_or_7(i):
				num_overlucky_numbers += 1
			if contains_4_or_7(n / i):
				num_overlucky_numbers += 1
		i += 1
	return num_overlucky_numbers

def contains_4_or_7(n):
	while n != 0:
		if n % 10 == 4 or n % 10 == 7:
			return True
		n //= 10
	return False
T = int(input())
for t in range(T):
	n = int(input())
	print(count_overlucky_numbers(n))


import math
tests = int(input())
for i in range(tests):
	num = int(input())
	ans = 0
	for j in range(1, math.ceil(num ** 0.5) + 1):
		if num % j == 0:
			string = str(j)
			if '4' in string or '7' in string:
				ans += 1
			other = num // j
			if other != j:
				string = str(other)
				if '4' in string or '7' in string:
					ans += 1
	print(ans)


import sys
f = sys.stdin
N = int(f.readline())
while N:
	n = int(f.readline())
	count = 0
	i = 1
	while i * i <= n:
		if n % i == 0:
			if '7' in str(i) or '4' in str(i):
				count += 1
			if '7' in str(n / i) or '4' in str(n / i):
				count += 1
		i += 1
	print(count)
	N -= 1


from math import sqrt
for i in range(int(input())):
	n = int(input())
	p = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			p.append(str(i))
			if n / i != i:
				p.append(str(n // i))
	c = 0
	for i in p:
		if '4' in i or '7' in i:
			c += 1
	print(c)


import sys, math

def main():
	cases = int(sys.stdin.readline())
	for case in range(cases):
		myCount = 0
		number = int(sys.stdin.readline())
		for c in str(number):
			if c == '4' or c == '7':
				myCount += 1
				break
		rt = int(math.sqrt(number))
		for i in range(2, rt + 1):
			if number % i == 0:
				for c in str(i):
					if c == '4' or c == '7':
						myCount += 1
						break
				for c in str(number / i):
					if c == '4' or c == '7':
						myCount += 1
						break
		print(myCount)
main()


def abc(n):
	flag = False
	while n > 0:
		x = n % 10
		if x == 4 or x == 7:
			return True
		n = n // 10
	return False
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(1, int(pow(n, 0.5)) + 1):
		if n % i == 0:
			ans += abc(i)
			if i != n // i:
				ans += abc(n // i)
	print(ans)


t = int(input())
for z in range(t):
	n = int(input())
	max = int(n ** (1 / 2))
	count = 0
	for i in range(1, max + 1):
		if n % i == 0:
			if '4' in str(i):
				count += 1
			elif '7' in str(i):
				count += 1
			if i != n / i:
				if '4' in str(n / i):
					count += 1
				elif '7' in str(n / i):
					count += 1
	print(count)


from math import *

def check(n):
	s = str(n)
	if '4' in s or '7' in s:
		return 1
	return 0
t = int(input())
for ele in range(t):
	n = int(input())
	j = int(sqrt(n))
	sum = 0
	for i in range(1, j + 1):
		if n % i == 0:
			sum += check(i)
			sum += check(n // i)
	if j * j == n and check(j):
		sum = sum - 1
	print(sum)


def Countlist(a):
	count = 0
	for i in range(1, int(a ** 0.5) + 1):
		if a % i == 0:
			if '4' in list(str(i)) or '7' in list(str(i)):
				count = count + 1
			if '4' in list(str(a / i)) or '7' in list(str(a / i)):
				count = count + 1
		if i == a / i:
			if '4' in list(str(i)) or '7' in list(str(i)):
				count = count - 1
	return count
N = int(input().strip())
for i in range(N):
	a = int(input().strip())
	print(Countlist(a))


from math import sqrt

def div(n):
	count = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			j = n / i
			if '4' in str(i) or '7' in str(i):
				count += 1
			if '4' in str(j) or '7' in str(j):
				count += 1 - (j == i)
	return count
t = int(input())
while t:
	n = int(input())
	print(div(n))
	t -= 1


for t in range(int(input())):
	n = int(input())
	count = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if '4' in str(i) or '7' in str(i):
				count += 1
			if ('4' in str(n // i) or '7' in str(n // i)) and i * i != n:
				count += 1
	print(count)


import math

def is_overlucky(value):
	value = str(value)
	if '4' in value or '7' in value:
		return True
	return False
t = int(input())
for z in range(t):
	num = int(input())
	count = 0
	for i in range(1, int(math.sqrt(num)) + 2):
		if num % i:
			continue
		if is_overlucky(i):
			count += 1
		if is_overlucky(num / i):
			count += 1
	print(count)


t = int(input())
for i in range(0, t):
	n = int(input())
	count = 0
	for j in range(1, int(pow(n, 1 / 2)) + 1):
		if n % j == 0:
			if '4' in str(j):
				count += 1
			elif '7' in str(j):
				count += 1
			f = n / j
			if j != pow(n, 1 / 2):
				if '4' in str(f):
					count += 1
				elif '7' in str(f):
					count += 1
	print(count)


def chk_overlucky(N):
	k = list(N)
	if '4' in k or '7' in k:
		return True
	else:
		return False

def find_d(n):
	count = 0
	root = int(n ** 0.5) + 1
	if n == 0:
		return 0
	for i in range(2, root):
		if n % i == 0:
			if chk_overlucky(str(i)):
				count = count + 1
			if chk_overlucky(str(int(n / i))):
				count = count + 1
	if chk_overlucky(str(n)):
		count = count + 1
	return count
t = int(input())
for i in range(t):
	N = input()
	print(find_d(int(N)))


def main():
	import math
	for T in range(int(input())):
		N = int(input())
		ans = 0
		for i in range(1, int(math.sqrt(N)) + 2):
			if N % i == 0:
				temp = str(i)
				temp2 = str(N // i)
				if '4' in temp or '7' in temp:
					ans += 1
				if '4' in temp2 or '7' in temp2:
					ans += 1
		print(ans)
main()


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def isOverLucky(n):
	s = str(n)
	for a in s:
		if a == '4' or a == '7':
			return True
	return False

def run():
	nb = int(input())
	nbDiv = 0
	for x in factors(nb):
		if isOverLucky(x):
			nbDiv += 1
	print(nbDiv)
for _ in range(int(input())):
	run()


from math import sqrt

def fact(n):
	count = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			c = str(n // i)
			k = str(i)
			if k != c:
				if '4' in k or '7' in k:
					count += 1
				if '4' in c or '7' in c:
					count += 1
			elif '4' in k or '7' in k:
				count += 1
	return count
t = int(input())
for i in range(t):
	n = int(input())
	ans = fact(n)
	print(ans)


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def overlucky(tab):
	s = 0
	for i in tab:
		if '4' in str(i) or '7' in str(i):
			s += 1
	return s
T = int(input())
for _ in range(T):
	n = int(input())
	tab = factors(n)
	print(overlucky(tab))


from sys import stdin

def sin():
	return stdin.readline()
for _ in range(int(input())):
	n = int(sin())
	c = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			a = str(i)
			b = str(n // i)
			if a == b:
				if '4' in a or '7' in a:
					c += 1
			else:
				if '4' in a or '7' in a:
					c += 1
				if '4' in b or '7' in b:
					c += 1
	print(c)


def contains47(s):
	return '4' in s or '7' in s
for _ in range(int(input())):
	n = int(input())
	i = 1
	ans = 0
	while i * i <= n:
		if n % i == 0:
			if contains47(str(i)):
				ans += 1
			if i * i != n and contains47(str(n // i)):
				ans += 1
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			a = str(i)
			b = str(n // i)
			if '4' in a or '7' in a:
				count += 1
			if i * i != n:
				if '4' in b or '7' in b:
					count += 1
	print(count)


import sys
import math
from time import time
from itertools import permutations, combinations
import collections
import functools
from fractions import gcd, Fraction
import string
import operator
import bisect

class timed(object):

	def __init__(self, func):
		self.func = func

	def __call__(self, *args):
		t1 = time()
		ret = self.func(*args)
		dif_time = time() - t1
		print('%s: returned %s in %f seconds' % (self.func.__name__, ret, dif_time))
		return ret

def comp(f1, f2, *args):
	t1 = time()
	r1 = f1(*args) if f1 is not None else None
	t2 = time()
	r2 = f2(*args) if f2 is not None else None
	t3 = time()
	res = '%5s: %s in %f\n%5s: %s in %f' % (f1.__name__ if f1 is not None else None, r1, t2 - t1, f2.__name__ if f2 is not None else None, r2, t3 - t2)
	if r1 != r2:
		dr = '!! DIFFERENT RESULTS !!'
		res = dr + '\n' + res + '\n' + dr
	print(res)

def factors(n):
	gaps = [1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6]
	(length, cycle) = (11, 3)
	(f, fs, next) = (2, [], 0)
	while f * f <= n:
		while n % f == 0:
			fs.append(f)
			n //= f
		f += gaps[next]
		next += 1
		if next == length:
			next = cycle
	if n > 1:
		fs.append(n)
	return fs

def divisors(n):
	facts = factors(n)
	factors_tuples = [(d, facts.count(d)) for d in set(facts)]
	nfactors = len(factors_tuples)
	if nfactors == 0:
		return
	f = [0] * nfactors
	while True:
		reduced = 1
		for v in [factors_tuples[x][0] ** f[x] for x in range(nfactors)]:
			reduced *= v
		yield reduced
		i = 0
		while True:
			f[i] += 1
			if f[i] <= factors_tuples[i][1]:
				break
			f[i] = 0
			i += 1
			if i >= nfactors:
				return

def alg(n):
	res = 0
	for d in divisors(n):
		if any((a in str(d) for a in ['4', '7'])):
			res += 1
	return res

def main():
	data = sys.stdin
	nb = int(data.readline())
	for icase in range(nb):
		i = int(data.readline().strip())
		res = alg(i)
		print(res)
main()


t = int(input())
import math
while t > 0:
	n = int(input())
	c = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			s = str(i)
			for j in s:
				if j == '7' or j == '4':
					c += 1
					break
			if n // i != i:
				x = str(n // i)
				for j in x:
					if j == '7' or j == '4':
						c += 1
						break
	print(c)
	t -= 1


import math
test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	count = 0
	for j in range(1, int(math.sqrt(n)) + 1):
		if n % j == 0:
			if '4' in str(j) or '7' in str(j):
				count = count + 1
			if j != n / j:
				if '4' in str(n / j) or '7' in str(n / j):
					count = count + 1
	print(count)


import math

def check(x):
	while x:
		if x % 10 == 4 or x % 10 == 7:
			return True
		x = x // 10
	return False
t = int(input())
while t:
	t -= 1
	n = int(input())
	count = 0
	a = int(math.sqrt(n))
	for i in range(1, a + 1):
		if n % i == 0:
			if check(i) == True:
				count += 1
			if check(n / i) == True:
				count += 1
	if a * a == n and check(a) == True:
		count -= 1
	print(count)


from math import sqrt

class Solution(object):

	def __init__(self):
		for _ in range(int(input())):
			n = int(input())
			ans = 0
			for i in range(1, int(sqrt(n)) + 1):
				if n % i == 0:
					if Solution.is_lucky_number(i):
						ans += 1
					y = n // i
					if y != i and Solution.is_lucky_number(y):
						ans += 1
				pass
			print(ans)
	pass

	@classmethod
	def is_lucky_number(cls, i):
		s = str(i)
		c = s.find('4')
		if c < 0:
			c = s.find('7')
		if c < 0:
			return False
		else:
			return True
		pass

def main():
	Solution()
	pass
main()


t = int(input())
for i in range(t):
	k = int(input())
	coun = 0
	for j in range(1, int(k ** 0.5) + 1):
		if k % j == 0:
			l = j
			while l != 0:
				x = l % 10
				if x == 4 or x == 7:
					coun = coun + 1
					break
				l = l // 10
			l = j
			x = k // l
			if x != l:
				z = x
				while z != 0:
					d = z % 10
					if d == 4 or d == 7:
						coun = coun + 1
						break
					z = z // 10
	print(coun)


for t in range(int(input())):
	n = int(input())
	ans = 0
	i = 1
	while i <= n ** 0.5:
		if n % i == 0:
			div1 = i
			div2 = n // i
			x = list(str(div1))
			y = list(str(div2))
			if '4' in x or '7' in x:
				ans += 1
			if y != x and ('4' in y or '7' in y):
				ans += 1
		i += 1
	print(ans)


from math import sqrt

def vlucky(n):
	if n == 0:
		return False
	if n % 10 == 4 or n % 10 == 7:
		return True
	return vlucky(int(n / 10))
t = int(input())
while t > 0:
	n = int(input())
	i = 1
	temp = []
	while i <= int(sqrt(n)):
		if n % i == 0:
			temp.append(i)
			temp.append(int(n / i))
		i += 1
	l = len(temp)
	i = 0
	ans = 0
	while i < l:
		if vlucky(temp[i]):
			ans += 1
		i += 1
	print(ans)
	t -= 1


from math import sqrt
t = int(input())
for _ in range(t):
	count = 0
	n = int(input())
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if '7' in str(i) or '4' in str(i):
				count += 1
			if ('7' in str(n // i) or '4' in str(n // i)) and i != n // i:
				count += 1
	print(count)