import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul, add from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 M = 17 def product(a, b): # A, B: vector add = lambda x, y:x+y mul = lambda x, y:x*y res = 0 for i, j in zip(a, b): res = add(res, mul(i, j)) res %= M return res def matmul(A, B): # A, B: matrix BT = [[B[i][j] for i in range(len(B))] for j in range(len(B[0]))] # 転置 return [[product(ai, bj) for bj in BT] for ai in A] def matpow(A, n): default = 1 B = [[default if i == j else 0 for j in range(len(A))] for i in range(len(A))] while n > 0: if n & 1: B = matmul(B, A) A = matmul(A, A) n >>= 1 return B def main(): Q = INT() A = [ [1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]] ans = [0]*Q for i in range(Q): n = INT() n -= 4 if n < 0: ans[i] = 0 continue mat = matpow(A, n) ans[i] = mat[0][0] print(*ans, sep="\n") if __name__ == '__main__': main()