#include #define VARNAME(x) #x #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using ld = long double; template vector Vec(int n, T v) { return vector(n, v); } template auto Vec(int n, Args... args) { auto val = Vec(args...); return vector(n, move(val)); } template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 17LL; constexpr ld PI = static_cast(3.1415926535898); template constexpr T INF = numeric_limits::max() / 10; struct Matrix { Matrix() : table(4, vector(4)) {} const vector& operator[](const int m) const { return table[m]; } vector& operator[](const int m) { return table[m]; } Matrix operator*(const Matrix& mat) const { Matrix ans; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { (ans[i][j] += (table[i][k] * mat[k][j]) % MOD) %= MOD; } } } return ans; } static Matrix Unit() { Matrix mat; for (int i = 0; i < 4; i++) { mat[i][i] = 1; } return mat; } vector> table; }; Matrix power(const Matrix& mat, const ll n) { if (n == 0) { return Matrix::Unit(); } if (n % 2 == 1) { return power(mat, n - 1) * mat; } else { const auto pp = power(mat, n / 2); return pp * pp; } } int main() { cin.tie(0); ios::sync_with_stdio(false); Matrix mat; mat[0][1] = 1; mat[1][2] = 1; mat[2][3] = 1; for (int j = 0; j < 4; j++) { mat[3][j] = 1; } int Q; cin >> Q; constexpr ll ans[] = {0, 0, 0, 0, 1}; for (int q = 0; q < Q; q++) { ll n; cin >> n; if (n <= 4) { cout << ans[n] << "\n"; } else { const auto ans = power(mat, n - 4); cout << ans[3][3] << "\n"; } } return 0; }