mod = 17 import sys import io, os input = sys.stdin.buffer.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): 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 #A**n def pow(a, n): b = [[0]*len(a) for i in range(len(a))] for i in range(len(a)): b[i][i] = 1 while n > 0: if n & 1 == 1: b = mul(a, b) a = mul(a, a) n = n>>1 return b A = [[1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]] q = int(input()) t1, t2, t3, t4 = 0, 0, 0, 1 for i in range(q): n = int(input()) B = pow(A, n-1) t = B[3][0]*t4+B[3][1]*t3+B[3][2]*t2+B[3][3]*t1 print(t%mod) if __name__ == '__main__': main()