import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n = ni() def f(a, b): res = 1 for i in range(a, a-b, -1): res *= i res %= 10 return res for _ in range(n): N = ni() ans = 0 for k in range(min(10, N+1)): ans += f(N, k) ans %= 10 print(ans)