def t(n: int) -> int: if n in [1, 2, 3]: return 0 elif n == 4: return 1 a, b, c, d = 1, 0, 0, 0 # n-1, ..., n-4 for _ in range(5, n + 1): a, b, c, d = (a + b + c + d) % 17, a, b, c return a Q = int(input()) for _ in range(Q): nq = int(input()) print(t(nq))