t = int(input()) assert 1 <= t <= 10 ** 5 for _ in range(t): n = int(input()) assert 0 <= n <= 10 ** 18 if n == 0: print(2) continue ans, now = 1, 1 while n >= 0: now *= n now %= 10 ans += now if now == 0: break n -= 1 print(ans % 10)