def Matprod(A, B, mod): N = len(A) temp = [[0] * N for i in range(N)] for i in range(N): for j in range(N): for k in range(N): temp[i][j] += A[i][k] * B[k][j] temp[i][j] %= mod return temp def Matpow(A, M, mod): N = len(A) Mat = [[0] * N for i in range(N)] for i in range(N): Mat[i][i] = 1 for i in range(64): if (M >> i) & 1: Mat = Matprod(Mat, A, mod) A = Matprod(A, A, mod) return Mat ans = [0, 0, 0, 1] Q = int(input()) for _ in range(Q): n = int(input()) n -= 1 if n <= 3: print(ans[n]) continue M = [[0] * 4 for i in range(4)] for i in range(4): M[0][i] = 1 if i < 3: M[i + 1][i] = 1 M = Matpow(M, n - 3, 17) print(M[0][0])