#include using namespace std; template using vec = vector; template using mat = vec>; template mat 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] += a[i][k] * b[k][j] % 17) %= 17; } } } return c; } template mat mat_pow(mat a, int64_t p) { mat r = a; for (int64_t i = p - 1; i; i >>= 1) { if (i & 1) r = mat_mul(r, a); a = mat_mul(a, a); } return r; } signed main() { ios::sync_with_stdio(false); mat f(4, vec(4)); for (int i = 0; i < 3; ++i) f[i][i + 1] = 1; for (int i = 0; i < 4; ++i) f[3][i] = 1; mat x(4, vec(1)); x[3][0] = 1; int Q; cin >> Q; while (Q--) { int64_t N; cin >> N; if (N == 1) { cout << 0 << endl; } else { cout << mat_mul(mat_pow(f, N - 1), x)[0][0] << endl; } } return 0; }