#include #define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; typedef vector vec; typedef vector mat; mat mul(mat &A, mat &B) { mat C(A.size(), vector(B[0].size())); REP(i, 0, A.size()) REP(j, 0, B[0].size()) REP(k, 0, B.size()) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % 17; return C; } mat pow(mat A, ll n) { mat B(A.size(), vec(A.size())); REP(i, 0, A.size()) B[i][i] = 1; while(n > 0) { if(n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main(void) { ll Q; cin >> Q; vector N(Q); REP(i, 0, Q) cin >> N[i]; mat A(4, vec(4)); A[0][0] = 1; A[0][1] = 1; A[0][2] = 1; A[0][3] = 1; A[1][0] = 1; A[1][1] = 0; A[1][2] = 0; A[1][3] = 0; A[2][0] = 0; A[2][1] = 1; A[2][2] = 0; A[2][3] = 0; A[3][0] = 0; A[3][1] = 0; A[3][2] = 1; A[3][3] = 0; REP(i, 0, Q) cout << pow(A, N[i] - 1)[3][0] << endl; }