# -*- coding: utf-8 -*- """ No.658 テトラナッチ数列 Hard https://yukicoder.me/problems/no/658 """ import sys from sys import stdin input = stdin.readline def solve(limit): loop = 0 loop_check= dict() res = [None, 0, 0, 0, 1] for i in range(5, limit+1): h = '{:02d}{:02d}{:02d}{:02d}'.format(res[-4], res[-3], res[-2], res[-1]) if h in loop_check: loop = loop_check[h] break else: loop_check[h] = i tmp = sum(res[-4:]) % 17 res.append(tmp) return res, loop def main(args): Q = int(input()) queries = [int(input()) for _ in range(Q)] tetra, looped = solve(max(queries)) if looped != 0: loop = len(tetra) - looped for q in queries: if q > loop: print(tetra[q % loop]) else: print(tetra[q]) else: for q in queries: print(tetra[q]) if __name__ == '__main__': main(sys.argv[1:])