T=[0,0,0,0,1] for i in range(10**6): T.append((T[-1]+T[-2]+T[-3]+T[-4])%17) Q=int(input()) for tests in range(Q): n=int(input()) if n<10**6: print(T[n]) else: print(T[n%4912 + 4912])