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()) print(T[n%4912])