T=int(input()) for tests in range(T): N=int(input()) ANS=0 now=1 x=N%10 for i in range(20): ANS+=now now*=x x-=1 now%=10 x%=10 print(ANS%10)