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