#!/usr/bin/python import sys M=17 def mul(a,b): r=[[0]*len(b[0]) for _ in range(len(a))] for y in range(len(a)): for x in range(len(b[0])): r[y][x]=sum(a[y][i]*b[i][x] for i in range(len(b)))%M return r A=[[1,1,1,1],[1,0,0,0],[0,1,0,0],[0,0,1,0]] E=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] for _ in range(int(sys.stdin.readline())): n=int(sys.stdin.readline()) a=A e=E while n: if n%2: e=mul(a,e) a=mul(a,a) n//=2 print(e[-1][-1])