import math case = int(input()) for i in range(case): n = int(input()) print(math.factorial(n)%10)