Given a number $n$, give the last digit of sum of all the prime numbers from 1 to $n$ inclusive.

-----Input:-----
- First line contains number of testcase $t$.
- Each testcase contains of a single line of input, number $n$. 

-----Output:-----
Last digit of sum of every prime number till n.

-----Constraints-----
- $1 \leq T \leq 10$
- $2 \leq N \leq 10^6$

-----Sample Input:-----
1
10

-----Sample Output:-----
7

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
import math
N = 10**6
sum_arr = [0] * (N + 1) 
def lprime():
    arr = [0] * (N + 1) 
    arr[0] = 1
    arr[1] = 1
    for i in range(2, math.ceil(math.sqrt(N) + 1)): 
        if arr[i] == 0: 
            for j in range(i * i, N + 1, i): 
                arr[j] = 1
      
    curr_prime_sum = 0

    for i in range(1, N + 1): 
        if arr[i] == 0: 
            curr_prime_sum += i 
        sum_arr[i] = curr_prime_sum 
        
n=int(input())
lprime()
for _ in range(n):
    x=int(input())
    print(sum_arr[x]%10)

# cook your dish here
# https://www.codechef.com/CSEP2020/problems/IRVS
for _ in range(int(input())):
    n = int(input())
    prime = [True for __ in range(n+1)]
    prime[:2] = [False, False]
    total = 0
    for i in range(2, n+1):
        if prime[i] is True:
            temp = i*2
            total += i
            while temp <= n:
                prime[temp] = False
                temp += i
    print(str(total)[-1])


def primalsum(n): 
	prime = [True] * (n + 1);p = 2;sum_ = 0
	while(p**2 <= n):
		if(prime[p] == True):
			i = p*2
			while(i <= n): prime[i] = False;i += p
		p += 1
	for i in range (2,n + 1): 
		if(prime[i]): sum_ += i 
	return sum_
for _ in range(int(input())):N = int(input());print(str(primalsum(N))[-1]) 

# cook your dish here
t=int(input())
for i in  range(t):
    sum1=0
    n=int(input())
    prime = [True for i in range(n + 1)] 
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 1
    prime[0]= False
    prime[1]= False
    for p in range(n+1):
        if prime[p]:
            sum1+=p
    print(sum1%10)
    
    


def SieveOfEratosthenes(n): 
	prime = [True for i in range(n+1)] ; ans = [];p = 2
	while (p * p <= n): 
		if (prime[p] == True): 
			for i in range(p * p, n+1, p):prime[i] = False
		p += 1
	for p in range(2, n+1): 
		if prime[p]:ans.append(p) 
	return ans
p = SieveOfEratosthenes(10**6+10)
for _ in range(int(input())):
	n = int(input());s = 0
	for i in range(len(p)):
		if p[i] > n:break
		else:s += p[i]
	print(s%10)

# irrelevant sum
def SieveOfEratosthenes(n): 
	prime = [True for i in range(n+1)] ; ans = []
	p = 2
	while (p * p <= n): 
		if (prime[p] == True): 
			for i in range(p * p, n+1, p): 
				prime[i] = False
		p += 1
      
    # Print all prime numbers 
	for p in range(2, n+1): 
		if prime[p]:ans.append(p) 
            #print p, 
	return ans
p = SieveOfEratosthenes(10**6+10)
for _ in range(int(input())):
	n = int(input())
	s = 0
	for i in range(len(p)):
		if p[i] > n:
			break
		else:
			s += p[i]
	print(s%10)

# cook your dish here
def sieve(n):
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime
for u in range(int(input())):
    n=int(input())
    p=sieve(n)
    s=0
    for i in range(2,n+1):
        if(p[i]==True):
            s+=i
    r=str(s)
    print(r[-1])


# cook your dish here
'''z=int(input())
for i in range(z):
	n=int(input())
	counta=[]
	for i in range(1,n+1):
		count=0
		for j in range(1,i+1):
			if i%j==0:
				count+=1
		if count==2:
			counta.append(i)
	print(sum(counta)%10)
import math
n=int(input())
for i in range(n):
	m=int(input())
	summ=0
	for num in range(2,m+1):
	      	if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):
	      		summ+=num
	print(summ%10)
import math

def is_prime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

n=int(input()) 
for i in range(n):
	m=int(input())
	summ=0
	for num in range(2,m+1):
	       	if is_prime(num):
	       		summ+=num 
	print(summ%10)''' 
def sumOfPrimes(n): 


    prime = [True] * (n + 1) 


    p = 2

    while p * p <= n: 

    

        if prime[p] == True: 

          

            i = p * 2

            while i <= n: 

                prime[i] = False

                i += p 

        p += 1    

           



    sum = 0

    for i in range (2, n + 1): 

        if(prime[i]): 

            sum += i 

    return sum

t=int(input())
for i in range(t):
	n=int(input())
	print(sumOfPrimes(n)%10)


# cook your dish here
def main(): 
      
    # Create a boolean array "prime[0..n]" and initialize 
    # all entries it as true. A value in prime[i] will 
    # finally be false if i is Not a prime, else true. 
    n=1000000
    prime = [True for i in range(n + 1)] 
    p = 2
    while (p * p <= n): 
          
        # If prime[p] is not changed, then it is a prime 
        if (prime[p] == True): 
              
            # Update all multiples of p 
            for i in range(p * 2, n + 1, p): 
                prime[i] = False
        p += 1
    prime[0]= False
    prime[1]= False
    # Print all prime numbers 
    s=[]
    s.append(0)
    for p in range(1,n + 1): 
        if prime[p]: 
            s.append(s[p-1]+(p))
        else:
            s.append(s[p-1])
    # print(s)
    t=int(input())
    for _ in range(t):
        num=int(input())
        print(s[num]%10)
main()

# cook your dish here
def sumOfPrimes(n): 
    # list to store prime numbers 
    prime = [True] * (n + 1) 
      
    # Create a boolean array "prime[0..n]" 
    # and initialize all entries it as true. 
    # A value in prime[i] will finally be 
    # false if i is Not a prime, else true. 
      
    p = 2
    while p * p <= n: 
        # If prime[p] is not changed, then 
        # it is a prime 
        if prime[p] == True: 
            # Update all multiples of p 
            i = p * 2
            while i <= n: 
                prime[i] = False
                i += p 
        p += 1    
           
    # Return sum of primes generated through 
    # Sieve. 
    sum = 0
    for i in range (2, n + 1): 
        if(prime[i]): 
            sum += i 
    return sum
for _ in range(int(input())):
    n=int(input())
    ans=sumOfPrimes(n)%10
    print(ans)

# cook your dish here
import math
N = 1000003
dp = [0] * (N + 1)
def seive():
    array = [0] * (N + 1)
    array[0] = 1
    array[1] = 1
    for i in range(2, math.ceil(math.sqrt(N) + 1)):
        if array[i] == 0:
            for j in range(i * i, N + 1, i):
                array[j] = 1
    runningPrimeSum = 0
    for i in range(1, N + 1):
        if array[i] == 0:
            runningPrimeSum += i
        dp[i] = runningPrimeSum
seive()
t=int(input())
for _ in range(t):
    n=int(input())
    print(dp[n]%10)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n+1)] 
	p = 2
	while(p * p <= n): 
		if (prime[p] == True): 
			for i in range(p * p, n + 1, p): 
				prime[i] = False
		p += 1
	c = 0
	for p in range(2, n+1): 
		if prime[p]: 
			c += p
	return c%10
for i in range(int(input())):
    c = SieveOfEratosthenes(int(input())) 
    print(c) 
    





import math

def sieve(x):
    l=[0]*x
    h=int(math.sqrt(x))
    for i in range(2,h+1):
        if(l[i-1]==0):
            for j in range(i*i,x+1,i):
                l[j-1]=1


    l1=[]
    for k in range(2,x+1):
        if l[k-1]==0:
            l1.append(k)
    print(sum(l1)%10)


def __starting_point():
    t=int(input())
    for i in range(t):
        n=int(input())
        sieve(n)

__starting_point()

# cook your dish here
def sumOfPrimes(n): 
    prime = [True] * (n + 1) 
    p = 2
    while p * p <= n:
        if prime[p] == True: 
            i = p * 2
            while i <= n: 
                prime[i] = False
                i += p 
        p += 1    
    sum = 0
    for i in range (2, n + 1): 
        if(prime[i]): 
            sum += i 
    return sum 
for _ in range(int(input())):    
    n=int(input())     
    c=sumOfPrimes(n) 
    print(c%10)

def prime(n):  
    l1 =[True]*(n + 1) 
    i=2
    while i*i<=n:
        if l1[i]==True: 
            a=i*2
            while a<=n: 
                l1[a]=False
                a=a+i 
        i=i+1    
    s1=0
    for i in range (2, n + 1): 
        if(l1[i]): 
            s1=s1+i 
    return s1
for _ in range(int(input())):
    n=int(input())
    s1=prime(n)
    ##print(s1)
    print(s1%10)



def sumOfPrimes(n): 

	prime = [True] * (n + 1) 

	
	p = 2
	while p * p <= n: 

		if prime[p] == True: 

			i = p * 2
			while i <= n: 
				prime[i] = False
				i += p 
		p += 1	

	sum = 0
	for i in range (2, n + 1): 
		if(prime[i]): 
			sum += i 
	return sum

for _ in range(int(input())):
    n = int(input())
    zzz = str(sumOfPrimes(n))
    print(zzz[-1])

def sumofprimes(n):
  prime=[True]*(n+1)
  p=2
  while(p*p<=n):
    if prime[p]==True:
      i=p*2
      while i<=n:
        prime[i]=False
        i+=p
    p+=1
  sum=0
  for i in range(2,n+1):
    if prime[i]:
      sum+=i
  return sum
def __starting_point():
  for _ in range(int(input())):
    n=int(input())
    print(sumofprimes(n)%10)
__starting_point()

def sumofprimes(n):
  prime=[True]*(n+1)
  p=2
  while(p*p<=n):
    if prime[p]==True:
      i=p*2
      while i<=n:
        prime[i]=False
        i+=p
    p+=1
  sum=0
  for i in range(2,n+1):
    if prime[i]:
      sum+=i
  return sum
def __starting_point():
  for _ in range(int(input())):
    n=int(input())
    print(sumofprimes(n)%10)
__starting_point()

# cook your dish here
n=1000001
sieve=[0]*(n+1)
sieve[0]=1
sieve[1]=1
for x in range(2,n+1):
    if(sieve[x]):
        continue
    for u in range(2*x,n+1,x):
        sieve[u]=1
for i in range(int(input())):
    n=int(input())
    count=0
    sum1=0
    #a1=[]
    for i in range(n+1):
        #if(count==n):
            #break
        if(sieve[i]==0):
            sum1+=i
            #a1.append(i)
            #count+=1
    print(sum1%10) 
    #print(a1)



def SieveOfEratosthenes(n): 
        
    prime = [True for i in range(n+1)] 
      
    p = 2
    while(p * p <= n): 
           
        if (prime[p] == True): 
               
            for i in range(p * p, n + 1, p): 
                prime[i] = False
        p += 1
    sum = 0
  
    for p in range(2, n+1): 
        if prime[p]: 
            sum += p
    return sum 
  



x = int(input())
for i in range(0,x):
    uptil = int(input())
    sum = SieveOfEratosthenes(uptil)
    print(sum%10)




# Python program to find sum of primes
# in range from 1 to n.
#code on gfg
# Returns sum of primes in range from
# 1 to n

def sumOfPrimes(n):
    # list to store prime numbers
    prime = [True] * (n + 1)

    # Create a boolean array "prime[0..n]"
    # and initialize all entries it as true.
    # A value in prime[i] will finally be
    # false if i is Not a prime, else true.

    p = 2
    while p * p <= n:
        # If prime[p] is not changed, then
        # it is a prime
        if prime[p] == True:
            # Update all multiples of p
            i = p * 2
            while i <= n:
                prime[i] = False
                i += p
        p += 1

        # Return sum of primes generated through
    # Sieve.
    sum = 0
    for i in range(2, n + 1):
        if (prime[i]):
            sum += i
    return sum


# Driver code
for _ in range(int(input())):
    n=int(input())
    ans=sumOfPrimes(n)
    ans=str(ans)
    print(ans[-1])



try:
    def findprimes(n,l):
        prime=[True for i in range(n+1)]
        p=2
        while p*p<=n:
            if prime[p]==True:
                for i in range(p*p,n+1,p):
                    prime[i]=False
            p+=1
        for i in range(2,n+1):
            if prime[i]==True:
                l.append(i)
        return l
    for _ in range(int(input())):
        n=int(input())
        l=[]
        findprimes(n,l)
        s=sum(l)
        print(s%10)
except:
    pass

for t in range(int(input())):
    n = int(input())
    A = [True for i in range(n+1)]
    A[0],A[1] = False,False
    i = 2
    while i**2 <= n:
        if A[i] == True:
            for j in range(i**2,n+1,i):
                A[j] = False
        i += 1
    sum = 0
    for i in range(2,n+1):
        if A[i] == True:
            sum += i
            if sum >= 10:
                sum %= 10
    print(sum)

for t in range(int(input())):
    n = int(input())
    A = [True for i in range(n+1)]
    A[0],A[1] = False,False
    i = 2
    while i**2 <= n:
        if A[i] == True:
            for j in range(i**2,n+1,i):
                A[j] = False
        i += 1
    sum = 0
    for i in range(2,n+1):
        if A[i] == True:
            sum += i
    print(sum%10)