#Fibonacchi sequence
import numpy as np

A = np.array([[1, 1, 1, 1], [1, 0, 0, 0], [
             0, 1, 0, 0], [0, 0, 1, 0]])

mod = 17


def mat_f(X):
    if X == 0:
        return np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
    elif X == 1:
        return A
    else:
        if X % 2 == 0:
            S = mat_f(X//2)
            return np.dot(S, S)%mod
        else:
            S = mat_f(X//2)
            return np.dot(np.dot(S, S), A)%mod


Q = int(input())
d = [int(input()) for i in range(Q)]
for i in range(Q):
    K=np.dot(mat_f(d[i]-1),np.array([1,0,0,0]))
    ans=(K[-1])%mod
    print(ans)