def tetra(n): seed = [0, 0, 0, 1] for _ in range(5, n + 1): seed += [sum(seed[-1:-5:-1]) % 17] return seed nq = int(input()) qs = [int(input()) for _ in range(nq)] res = tetra(max(qs)) for q in qs: print(res[q - 1] % 17)