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