# -*- 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_start = -1 # res[]中の数字の並びで繰り返しが発生するスタート地点 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_start = loop_check[h] break else: loop_check[h] = i tmp = sum(res[-4:]) % 17 res.append(tmp) return res, loop_start def main(args): Q = int(input()) queries = [int(input()) for _ in range(Q)] tetra, loop_start = solve(max(queries)) tetra_mod = tetra[loop_start:] # 繰り返し部分だけのテーブル orikaeshi = len(tetra) # この数字以上は繰り返しパタンに入っている cycle = orikaeshi - loop_start # 繰り返しの周期 for q in queries: if q >= orikaeshi: print(tetra_mod[(q-loop_start)%cycle]) # print(tetra[(q-loop_start)%cycle + loop_start]) else: print(tetra[q]) if __name__ == '__main__': main(sys.argv[1:])