import math T = int(input()) L = [] for _ in range(T): L.append(int(input())) def ans(a): print(math.floor(math.e*math.factorial(a))%10) for _ in L: ans(_)