import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict def getlist(): return list(map(int, input().split())) mod = 17 def mul(A, B): C = [[0] * len(B[0]) for i in range(len(A))] for i in range(len(A)): for k in range(len(B)): for j in range(len(B[0])): C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod return C def matrixPow(A, n, N): B = [[0] * N for i in range(N)] for i in range(N): B[i][i] = 1 while n > 0: if n & 1 == 1: B = mul(A, B) A = mul(A, A) n = n >> 1 return B #処理内容 def main(): Q = int(input()) A = [[1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]] for i in range(Q): n = int(input()) B = matrixPow(A, n - 1, 4) s = mul(B, [[1], [0], [0], [0]]) ans = s[3][0] % 17 print(ans) if __name__ == '__main__': main()