import sys, math t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) f = math.factorial(n) print(f % 10)