import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def main(): tt=[0,0,0,1,1] while 1: tt.append((tt[-1]*2-tt[-5])%17) if tt[-1]==1 and tt[-2]==0 and tt[-3]==0 and tt[-4]==0: break cycle=len(tt)-4 q=II() for _ in range(q): n=II()-1 print(tt[n%cycle]) main()