import sys T = int(input()) for i in range(T): N = int(input()) if N == 0: print(2) continue temp = 1 ans = 0 for i in range(N, -1, -1): ans = (ans + temp) % 10 temp = (temp * i) % 10 if temp == 0: break print(ans)