a=[1,2,5,6,5,6,7,0,1,0] T = int(input()) for i in range(T): n = int(input()) if n == 0: print(2) else: print(a[n%10])