#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, m, n) for(int i=int(m);i vec; typedef vector mat; const int M = 17; mat mul(mat &A, mat &B) { mat C(A.size(), vec(B[0].size())); for (int i = 0; i < A.size(); i++) { for (int k = 0; k < B.size(); k++) { for (int j = 0; j < B[0].size(); j++) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M; } } } return C; } mat pow(mat A, ll n) { mat B(A.size(), vec(A.size())); for (int i = 0; i < A.size(); i++) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main() { cin.tie(0); ios::sync_with_stdio(false); int Q; cin >> Q; rep(i, 0, Q) { ll n; cin >> n; if(n < 4){ cout << 0 << endl; continue; }else if(n == 4){ cout << 1 << endl; continue; } mat A({ {1, 1, 1, 1}, {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0} }); A = pow(A,n-4); cout << A[0][0] << endl; } return 0; }