Little Gaurav is very fond of numbers and sequences. One day his teacher tells him to find a strange sequence.    

$S=\sum_{i=0,2^i\leq n}\sum_{j=0}^n2^{2^i+2j}$

Since this sequence looks a bit difficult, the teacher tells him to find the last digit of ${S}$.  

Little Gaurav is confused because he cannot solve the problem and leaves this problem to the worthy programmers of the world. Help little Gaurav in finding the solution.   

Input Format 

The first line contains ${T}$, the number of test cases. 

${T}$ lines follow, each line containing an integer, $N$.   

Output Format 

For each testcase, print the last digit of ${S}$ in one line.    

Constraints 

$1\leq T\leq1000$ 

$1\leq N\leq10^{15}$  

Sample Input     

3
1
2
3

Sample Output   

0
6
0

Explanation 

For n=1, only i=0 is valid. So S is $2^{2^{0}+0}+2^{2^{0}+2}=10$. Hence last digit of S is 0. 

For n=2, only i=0 and 1 are valid. So S is 

S1(for i=0) is $2^{2^{0}+0}+2^{2^{0}+2}+2^{2^{0}+4}=42$. 

S2(for i=1) is $2^{2^{1}+0}+2^{2^{1}+2}+2^{2^{1}+4}=84$. 

So last digit of S is 6.

Source: hackerrank | Difficulty: MEDIUM
Tags: Matrices


Solutions:
for _ in range(int(input())):
	(n, sum, cur) = (int(input()), 0, 1)
	while cur <= n:
		sum += pow(2, cur, 10)
		cur *= 2
	sum = sum * (1 + (4 if n % 2 == 1 else 0)) % 10
	print(sum)


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


def sum1(x):
	return 2 if x & 1 == 0 else 0

def sum2(x):
	return 4 if x & 1 == 0 else 0

def sum4(x):
	return 6 if x & 1 == 0 else 0

def f(x):
	ret = 0
	if x >= 1:
		ret += sum1(x)
	if x >= 2:
		ret += sum2(x)
	i = 4
	while i <= x:
		ret += sum4(x)
		i <<= 1
	return ret % 10
t = int(input())
for _ in range(t):
	print(f(int(input())))


def last_digit(n):
	return [6, 2, 4, 8][n % 4]
T = int(input())
for t in range(T):
	N = int(input())
	s1 = 0
	i = 1
	while i <= N:
		s1 += last_digit(i)
		i *= 2
	s2 = [1, 5][N % 2]
	print(s1 * s2 % 10)


t = int(input())
for j in range(t):
	n = int(input())
	i = 0
	ans1 = 0
	s1 = 0
	while 2 ** i <= n:
		s1 += 1
		i += 1
	if s1:
		ans1 += 2
		s1 -= 1
	if s1:
		ans1 += 4
		s1 -= 1
	ans1 += 6 * s1
	ans2 = 1
	if n & 1:
		ans2 += 4
	ans1 *= ans2
	ans1 %= 10
	print(ans1)


import math

def calc(n):
	if n % 2 == 1:
		return 0
	else:
		n = int(n / 2)
		pow2 = math.floor(math.log2(n))
		sa2 = pow2 % 5
		if sa2 == 1:
			return 2
		elif sa2 == 2:
			return 8
		elif sa2 == 3:
			return 4
		elif sa2 == 4:
			return 0
		else:
			return 6
t = int(input())
for x in range(t):
	print(calc(int(input())))


t = int(input())
for _ in range(t):
	n = int(input())
	ndig = 1 + 4 * (n % 2)
	for i in range(n):
		if 2 ** i > n:
			break
		lim = i
	idig = 6 * lim
	if lim == 0:
		idig = 2
	print(ndig * (idig % 10) % 10)


from sys import stdin
from math import log
T = int(stdin.readline())
for _ in range(T):
	N = int(stdin.readline())
	a = {1: 1, 2: 1, 3: 5}[(2 * N + 1) % 4]
	b = int(log(N, 2))
	ans = a * 2
	if b > 0:
		ans += a * 4
	if b > 1:
		ans += a * 6 * (b - 1)
	print(ans % 10)


import math
T = int(input())
for i in range(T):
	N = int(input())
	if N % 2 == 1:
		print(0)
	elif N == 0:
		print(2)
	else:
		i = int(math.log(N, 2))
		print(6 * i % 10)


from math import log

def main():
	t = int(input())
	for x in range(t):
		n = int(input())
		i = 0
		rtn = int(log(n, 2))
		x = 0
		a = 0
		val = sum(n)
		for i in range(rtn + 1):
			if i == 0:
				b = 2 * val
				x = x + b
			if i == 1:
				b = 4 * val
				x = x + b
			if i >= 2:
				break
		if i >= 2:
			b = 6 * val
			a = a + b
			x = x + a * (rtn - 2 + 1)
		print(x % 10)

def sum(n):
	if n % 2 == 0:
		s = 6
	else:
		s = 0
	return s
main()


n = int(input())
ans = 0
for i in range(n):
	inp = int(input())
	N = inp
	i = 0
	while N - 2 ** i >= 0:
		i += 1
	if i == 0:
		if N % 2 == 0:
			ans = 2
		else:
			ans = 0
	elif N % 2 == 0:
		ans = 6 * (i - 1) % 10
	else:
		ans = 0
	print(ans)


def solve(n):
	x = 1
	sum = 0
	y = 0
	even = True if (n + 1) % 2 == 0 else False
	while x <= n:
		if not even:
			if y == 0:
				sum += 2
			elif y == 1:
				sum += 4
			else:
				sum += 6
		y += 1
		x = x * 2
	return sum % 10
for t in range(0, int(input())):
	print(solve(int(input())))


def sum1(n):
	inv3 = 7
	p4 = pow(4, n + 1, 10)
	res = (p4 - 1) * inv3
	res = res % 10
	return res

def sum2(n):
	m = 0
	p2 = 1
	while p2 <= n:
		p2 = p2 * 2
		m = m + 1
	if p2 > n:
		m = m - 1
	if m == 0:
		return 2
	return 6 * m % 10
T = int(input())
while T:
	T = T - 1
	N = int(input())
	s1 = sum1(N)
	s2 = sum2(N)
	S = s1 * s2 % 10
	print(S)


import math
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		print(6 * math.floor(math.log(n, 2)) % 10)


def main():
	for case in range(int(input())):
		n = int(input())
		d_sum_j = 5 if n % 2 == 1 else 1
		d_sum_i = 0
		i = 0
		while 2 ** i <= n:
			d_sum_i += l(2 ** i)
			i += 1
		d_sum = d_sum_i * d_sum_j
		print(d_sum % 10)

def l(p):
	return [6, 2, 4, 8][p % 4]
main()


from math import log2, floor
t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		sum_j = 1
		lg = floor(log2(n))
		if lg == 0:
			print(2)
		else:
			a = [0, 6, 2, 8, 4]
			print(a[lg % 5])


from math import log2 as ln
for T in range(int(input())):
	N = int(input())
	x = 2 if N == 1 else 6 * int(ln(N))
	y = 1 + N // 2 * 6 + (N + 1) // 2 * 4
	print(x % 10 * y % 10 % 10)


import math
for _ in range(int(input())):
	N = int(input())
	test = int(math.log2(N))
	if test == 0:
		S1 = 2
	else:
		S1 = 6 * test % 10
	if N % 2 == 0:
		S2 = 1
	else:
		S2 = 5
	print(S1 * S2 % 10)


def solve(n):
	if n % 2 == 1:
		return 0
	else:
		i = 0
		while n > 1:
			n >>= 1
			i += 1
		if i == 0:
			return 2
		else:
			return i * 6 % 10
T = int(input())
for _ in range(T):
	print(solve(int(input())))


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


from math import log
t = int(input())
for i in range(t):
	n = int(input())
	l = int(log(n, 2))
	res = 2 if n % 2 == 0 else 0
	for j in range(1, l + 1):
		if j != 1:
			res += 6 if n % 2 == 0 else 0
		else:
			res += 4 if n % 2 == 0 else 0
		res = res % 10
	print(res % 10)


import math
T = int(input())
for _ in range(T):
	N = int(input())
	i = int(math.log(N, 2))
	ri = 6 * i if i else 2
	rj = 5 if N % 2 else 1
	print(ri * rj % 10)


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


import math
t = int(input())
while t:
	n = int(input())
	Sum_1 = 7 * (pow(4, n + 1, 10) - 1) % 10
	Max = math.log(n) / math.log(2)
	Sum_2 = sum((pow(2, 2 ** i, 10) for i in range(int(Max) + 1)))
	print(Sum_1 * Sum_2 % 10)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	tmp = pow(4, n + 1, 10) - 1
	k = 0
	while n > 1:
		k += 1
		n //= 2
	print(2 * k * tmp % 10)


from math import log
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		print(6 * int(log(n, 2)) % 10)


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


def do(n):
	if n & 1:
		return 0
	elif n == 2:
		return 6
	return [4, 0, 6, 2, 8][n.bit_length() % 5]
for _ in range(int(input().strip())):
	print(do(int(input().strip())))


import math
t = int(input())
for i in range(0, t):
	n = int(input())
	d = n % 10
	if d % 2 == 0:
		z = math.log2(n)
		y = int(z)
		y = y % 5
		y = y * 6
		print(y % 10)
	else:
		print('0')


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


from math import log
for _ in range(int(input())):
	n = int(input())
	s2 = 7 * (pow(4, n + 1, 10) - 1) % 10
	m = log(n) / log(2)
	s1 = sum((pow(2, 2 ** i, 10) for i in range(int(m) + 1)))
	print(s1 * s2 % 10)


from math import log
T = int(input().strip())
D = [0, 6, 2, 8, 4]
for t in range(0, T):
	N = int(input().strip())
	K = int(log(N, 2))
	if N % 2 == 0:
		print(D[K % 5])
	else:
		print(0)


print(*((lambda n: (5 if n % 2 else 1) * ([6, 2, 8, 4, 0][(n.bit_length() - 2) % 5] if n.bit_length() != 1 else 2) % 10)(int(input())) for _ in range(int(input()))), sep='\n')


def main():
	for i in range(int(input())):
		n = int(input())
		if n % 2:
			print(0)
		else:
			print(6 * (n.bit_length() - 1) % 10)
main()


inf = float('inf')
read_ints = lambda : list(map(int, input().split()))

def powermod(x, k, MOD):
	if k == 0:
		return 1
	(ans, l) = (x % MOD, 1)
	while 2 * l <= k:
		ans = ans * ans % MOD
		l *= 2
	return ans * powermod(x, k - l, MOD) % MOD

def solve(N):
	ans = 0
	i = 0
	while 2 ** i <= N:
		ans = ans + powermod(2, 2 ** i, 10)
		i += 1
	return (powermod(4, N + 1, 10) - 1) * ans * 27 % 10
T = int(input())
for _ in range(T):
	N = int(input())
	print(solve(N))


import math
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = int(math.log(n, 2))
	if n % 2 == 1:
		print(0)
	elif n == 2:
		print(6)
	else:
		print(6 * l % 10)


from math import log2

def compute(n):
	k = int(log2(n))
	a = 1 + 4 * (n % 2)
	if k == 0:
		return 2 * a % 10
	return 6 * k * a % 10
T = int(input())
for t in range(T):
	N = int(input())
	print(compute(N))


def custNum(n):
	count = 0
	subtrahend = 1
	while n > 0:
		count += 1
		n -= subtrahend
		subtrahend *= 2
	if count % 5 == 1:
		return 6
	elif count % 5 == 2:
		return 2
	elif count % 5 == 3:
		return 8
	elif count % 5 == 4:
		return 4
	else:
		return 0
T = int(input())
for t in range(T):
	N = int(input())
	if N % 2 == 1:
		print('0')
	else:
		print(custNum(N / 2))


import math, sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	n = 7 * (pow(4, N + 1, 10) - 1) % 10
	max_i = math.log(N) / math.log(2)
	m = sum((pow(2, 2 ** i, 10) for i in range(int(max_i) + 1)))
	print(n * m % 10)


import math
t = int(input())
for i in range(t):
	n = int(input())
	R = math.pow(4, (n + 1) % 4) % 10
	if R == 2:
		r1 = 7
	elif R == 4:
		r1 = 1
	elif R == 8:
		r1 = 9
	else:
		r1 = 5
	if n == 1:
		r2 = 2
	elif n == 2 or n == 3:
		r2 = 6
	else:
		r2 = int(math.log2(n)) * 6 % 10
	print(r1 * r2 % 10)


T = int(input())
for i in range(T):
	n = int(input())
	if n == 2:
		print(6)
		continue
	if n % 2 == 1:
		print(0)
		continue
	print((len(bin(n)) - 3) * 6 % 10)


import math
ctest = int(input())
for itest in range(ctest):
	n = int(input())
	if n % 2 == 1:
		sum1 = 5
	else:
		sum1 = 1
	maxi = int(math.log(n, 2))
	if maxi == 0 or maxi % 5 == 2:
		sum2 = 2
	elif maxi % 5 == 1:
		sum2 = 6
	elif maxi % 5 == 3:
		sum2 = 8
	elif maxi % 5 == 4:
		sum2 = 4
	else:
		sum2 = 0
	print(sum1 * sum2 % 10)


from math import log2, floor
rem = [6, 2, 4, 8]
T = int(input())
for cntT in range(T):
	N = int(input())
	maxi = floor(log2(N))
	s = 0
	for i in range(maxi + 1):
		m4 = pow(2, i, 4)
		if N % 2 == 0:
			s += 6 * rem[m4]
			s %= 10
	print(s)


from math import log, floor
T = int(input().strip())
for _ in range(T):
	N = int(input().strip())
	if N % 2 == 1:
		print(0)
	else:
		order = [0, 6, 2, 8, 4]
		print(order[floor(log(N, 2)) % 5])


for t in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		ans = 0
		i = 1
		while i <= n:
			if i == 1:
				ans += 2
			elif i == 2:
				ans += 4
			else:
				ans += 6
			i *= 2
		print(ans % 10)


import sys
import math
for a0 in range(int(input())):
	N = int(input())
	m = math.log(N, 2)
	m = int(m)
	print(6 * m * (1 + N % 2 * 4) % 10)


import math
t = int(input())
while t:
	n = int(input())
	if n % 2 == 1:
		a = 0
	else:
		a = int(math.log(n) / math.log(2)) * 6
	print(a % 10)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = 2 if n == 1 else 6 * (n.bit_length() - 6)
	r = 5 if n % 2 else 1
	print(l * r % 10)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	if n & 1 == 1:
		ret = 5
	else:
		ret = 1
	count = 0
	while n > 0:
		count += 1
		n >>= 1
	if count == 1:
		ret *= 2
	else:
		ret *= 6 * (count - 1)
	print(ret % 10)


import math
t = int(input())
for __ in range(t):
	n = int(input())
	y = int(math.log(n) / math.log(2)) + 1
	s = 0
	if y == 1:
		s = 2
	else:
		s = (y - 1) * 6
	a = s % 10
	b = 5
	if n % 2 == 0:
		b = 1
	print(a * b % 10)


import math

def find(n):
	if n == 1:
		return 0
	if n == 2:
		return 6
	if n == 3:
		return 0
	L = int(math.log(n, 2))
	ans = 0
	if L < 100:
		for i in range(L + 1):
			ans += pow(2, 2 ** i, 10) * (pow(4, n + 1, 10) - 1)
			ans %= 10
		ans *= 7
		ans %= 10
		return ans
for _ in range(int(input())):
	print(find(int(input())))


import math
for _ in range(int(input())):
	n = int(input())
	k = int(math.log(n, 2))
	A = 0
	for i in range(k + 1):
		A += pow(2, 2 ** i, 10)
	B = pow(4, n + 1, 10)
	B -= 1
	B *= 7
	B %= 10
	print(A * B % 10)


T = int(input())
for t in range(T):
	N = int(input())
	s = 0
	i = 1
	while i <= N:
		s += pow(2, i, 10)
		i <<= 1
	s = s * (pow(4, N + 1, 10) - 1) * 7 % 10
	print(s)


def find_i(p):
	p >>= 1
	ans = 0
	while p:
		ans += 1
		p >>= 1
	return ans
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	if n & 1:
		x = 5
	else:
		x = 1
	i = find_i(n)
	if i:
		y = 6 * i
	else:
		y = 2
	print(x * y % 10)


for i in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		n_base_2 = bin(n)[2:]
		l = len(n_base_2)
		print(6 * (l - 1) % 10)


from math import log2
T = int(input())
for run in range(T):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		print(6 * int(log2(n)) % 10)


def bitize(x):
	L = []
	while x > 0:
		L.append(x % 2)
		x //= 2
	return L

def pow_mod(a, b, m):
	b_bits = bitize(b)
	a_powers = [0 for x in b_bits]
	a_powers[0] = a % m
	if b_bits[0]:
		total = a % m
	else:
		total = 1
	for i in range(1, len(b_bits)):
		a_powers[i] = a_powers[i - 1] * a_powers[i - 1] % m
		if b_bits[i]:
			total *= a_powers[i]
			total %= m
	return total
T = int(input())
for _ in range(0, T):
	N = int(input())
	log_n = 0
	temp_n = N
	total = 0
	while temp_n > 0:
		temp_n //= 2
		log_n += 1
	for i in range(0, log_n):
		total += pow_mod(2, pow(2, i), 10) * (pow_mod(4, N + 1, 10) - 1) * 7
		total %= 10
	print(total)


import sys

def solve(n):
	print('\nn=%d' % n, file=sys.stderr)
	sm = 0
	(i, p2i) = (0, 1)
	while p2i <= n:
		print('i=%d' % i, file=sys.stderr)
		if i == 0:
			p22i = 2
		elif i == 1:
			p22i = 4
		else:
			p22i = 6
		print('p22i=%d' % p22i, file=sys.stderr)
		sp4j = 1 + 4 * (n // 2) + 6 * (n // 2)
		if n % 2 == 1:
			sp4j += 4
		sp4j %= 10
		print('sp4j=%d' % sp4j, file=sys.stderr)
		sm += p22i * sp4j % 10
		sm %= 10
		i += 1
		p2i *= 2
	return sm
t = int(input())
for _ in range(t):
	n = int(input())
	print(solve(n))


from math import floor, log2
T = int(input().strip())
br = [6, 2, 8, 4, 0]
ar = [5, 1]
for i in range(T):
	N = int(input().strip())
	a = ar[int(N + 1) % 2]
	temp = floor(log2(N))
	b = 2 if temp == 0 else br[int(temp % 5 - 1)]
	print(int(a * b % 10))


import math
t = int(input())
for i in range(t):
	n = int(input())
	x = int(math.log2(n)) + 1
	if x == 1:
		temp = 2
	else:
		temp = (x - 1) * 6
	a = temp % 10
	if n % 2 == 0:
		tmp = 1
	else:
		tmp = 5
	print(a * tmp % 10)


from math import log2, floor

def game(n):
	karr = [0, 6, 2, 8, 4]
	k = floor(log2(n))
	a1 = karr[k % 5]
	a2 = 0
	if n % 2 == 0:
		a2 = 1
	else:
		a2 = 5
	return a1 * a2 % 10
for _ in range(int(input())):
	print(game(int(input())))


def calc(n):
	s = 1
	if n % 2 == 0:
		s += 10 * (n // 2)
	else:
		s += 10 * (n // 2) + 4
	return s % 10
T = int(input())
for a in range(T):
	N = int(input())
	s = 0
	t = 1
	while t <= N:
		s = (s + pow(2, t, 10) * calc(N)) % 10
		t *= 2
	print(s)


import math
for _ in range(int(input())):
	n = int(input())
	s = 0
	a = int(math.log(n) / math.log(2))
	b = a + 1
	s = 2 if b == 1 else (b - 1) * 6
	m = s % 10
	temp = 5
	if n % 2 == 0:
		temp = 1
	print(m * temp % 10)


from math import log
for _ in range(int(input())):
	n = int(input())
	if n % 2:
		print(0)
	else:
		print(int(log(n, 2)) * 6 % 10)


def f(n):
	if n % 2 == 0:
		return 1
	else:
		return 5

def g(n):
	i = 0
	b = f(n)
	s = 0
	s = (s + 2 * b) % 10
	i = 2
	while i <= n:
		a = pow(2, i, 10) * b
		s = (s + a) % 10
		i *= 2
	return s
T = int(input())
for t0 in range(T):
	N = int(input())
	print(g(N))


def S_brutforce(n):
	s = 0
	i = 0
	while 2 ** i <= n:
		for j in range(0, n + 1):
			s += 2 ** (2 ** i + 2 * j)
		i += 1
	return s

def S(n):
	i = n
	k = 0
	while i != 0:
		i //= 2
		k += 1
	if k == 1:
		s1 = 2
	else:
		s1 = [6, 2, 8, 4, 0][(k - 2) % 5]
	s2 = 1 if n % 2 == 0 else 5
	return s1 * s2 % 10

def test():
	for n in range(1, 100):
		s = S(n)
		assert s % 10 == S_brutforce(n) % 10
		print('{:4} {}'.format(n, s % 10))
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		s = S(n)
		print(s)


for _ in range(int(input())):
	(n, sum, cur) = (int(input()), 0, 1)
	while cur <= n:
		sum += pow(2, cur, 10)
		cur *= 2
	sum = sum * (1 + (4 if n % 2 == 1 else 0)) % 10
	print(sum)


import os
import sys

def S_brutforce(n):
	s = 0
	i = 0
	while 2 ** i <= n:
		for j in range(0, n + 1):
			s += 2 ** (2 ** i + 2 * j)
		i += 1
	return s

def S(n):
	i = n
	k = 0
	while i != 0:
		i //= 2
		k += 1
	if k == 1:
		s1 = 2
	else:
		s1 = [6, 2, 8, 4, 0][(k - 2) % 5]
	s2 = 1 if n % 2 == 0 else 5
	return s1 * s2 % 10

def test():
	for n in range(1, 100):
		s = S(n)
		assert s % 10 == S_brutforce(n) % 10
		print('{:4} {}'.format(n, s % 10))
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		s = S(n)
		print(s)


import math as np

def val(n):
	if n == 0:
		return 2
	elif n == 1:
		return 4
	else:
		return 6
T = int(input())
for _ in range(T):
	N = int(input())
	s1 = 5
	if N % 2 == 0:
		s1 = 1
	m = int(np.log10(N) / np.log10(2.0))
	s = 0
	for i in range(0, m + 1):
		s += val(i)
	print(s1 * s % 10)


from math import log2, floor
for _ in range(int(input())):
	n = int(input())
	ld_4sum = 5 if n % 2 else 1
	ld_pow2 = lambda k: 1 if k == 0 else [6, 2, 4, 8][k % 4]
	ld_2sum = sum((ld_pow2(1 << i) for i in range(0, floor(log2(n) + 1)))) % 10
	print(ld_2sum * ld_4sum % 10)


def S_brutforce(n):
	s = 0
	i = 0
	while 2 ** i <= n:
		for j in range(0, n + 1):
			s += 2 ** (2 ** i + 2 * j)
		i += 1
	return s

def S(n):
	i = n
	k = 0
	while i != 0:
		i //= 2
		k += 1
	if k == 1:
		s1 = 2
	else:
		s1 = [6, 2, 8, 4, 0][(k - 2) % 5]
	s2 = 1 if n % 2 == 0 else 5
	return s1 * s2 % 10

def test():
	for n in range(1, 100):
		s = S(n)
		assert s % 10 == S_brutforce(n) % 10
		print('{:4} {}'.format(n, s % 10))
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		s = S(n)
		print(s)


def S_brutforce(n):
	s = 0
	i = 0
	while 2 ** i <= n:
		for j in range(0, n + 1):
			s += 2 ** (2 ** i + 2 * j)
		i += 1
	return s

def S(n):
	i = n
	k = 0
	while i != 0:
		i //= 2
		k += 1
	if k == 1:
		s1 = 2
	else:
		s1 = [6, 2, 8, 4, 0][(k - 2) % 5]
	s2 = 1 if n % 2 == 0 else 5
	return s1 * s2 % 10

def test():
	for n in range(1, 100):
		s = S(n)
		assert s % 10 == S_brutforce(n) % 10
		print('{:4} {}'.format(n, s % 10))
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print(0)
	else:
		s = S(n)
		print(s)


import math
t = int(input())
while t:
	n = int(input())
	s = 0
	x = int(math.log(n, 2))
	if n == 0:
		print('2')
	else:
		if n % 2 == 0:
			j = 1
		else:
			j = 5
		if x < 4:
			for i in range(0, x + 1):
				s = s + 2 ** 2 ** i * j
		else:
			s = 2 * j + 4 * j + 16 * j + 6 * (x - 2) * j
	print(s % 10)
	t -= 1


import math
for _ in range(int(input())):
	n = int(input())
	x = math.log(n) / math.log(2)
	y = int(x) + 1
	s = 0
	if y == 1:
		s = 2
	else:
		s = (y - 1) * 6
	a = s % 10
	b = 5
	if n % 2 == 0:
		b = 1
	print(a * b % 10)