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