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