def tetra(qs): seed = [0, 0, 0, 1] for step in range(0, 4): if step + 1 in qs: yield (step + 1, seed[step]) for step in range(5, max(qs) + 1): seed += [(sum(seed) % 17)] seed = seed[1:] if step in qs: yield (step, seed[-1]) nq = int(input()) qs = [int(input()) for _ in range(nq)] t = dict(tetra(qs)) for q in qs: print(t[q])