from copy import deepcopy #=========================================== def m(A,B): C=[[0]*4 for i in range(4)] for i in range(4): for j in range(4): X=0 for k in range(4): X+=A[i][k]*B[k][j] X%=17 C[i][j]=X return C #=========================================== Q=int(input()) X=[0]*Q M=[[1,1,1,1],[1,0,0,0],[0,1,0,0],[0,0,1,0]] for i in range(Q): N=int(input()) A=[[1*(i==j) for i in range(4)] for j in range(4)] B=deepcopy(M) while N>0: if N%2: A=m(A,B) N>>=1 B=m(B,B) X[i]=A[-1][-1] print("\n".join(map(str,X)))