t = int(input()) # e = 1/1 + 1/2! + 1/3! + ... # e(N!) = N!/1! + N!/2! + N!/3! + ... + N + 1 + (小さい数) for _ in range(t): n = int(input()) ans = 0 tmp = 1 for i in range(min(n+1, 5)): ans += tmp ans %= 10 tmp *= n - i print(ans)