def main(): Q = int(input()) N = tuple(int(input()) for _ in [0] * Q) tetra = [0, 0, 0, 1, 1] apnd = tetra.append i = 1 while 1: if all((not tetra[i], not tetra[i+1], not tetra[i+2], tetra[i+3] == 1)): break else: apnd((tetra[i] + tetra[i+1] + tetra[i+2] + tetra[i+3]) % 17) i += 1 for n in N: print(tetra[(n-1) % (len(tetra) - 4)]) main()