def solve(): N=int(input()) T=0 X=1 for i in range(10): T+=X X*=N-i; X%=10 return T%10 #================================================== import sys input=sys.stdin.readline write=sys.stdout.write T=int(input()) write("\n".join(map(str,[solve() for t in range(T)])))