#include #include using namespace std; using ll = long long; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) template struct MInt { long long val; constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; } MInt operator+(const MInt& n) const { return MInt(val) += n; } MInt operator*(const MInt& n) const { return MInt(val) *= n; } MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; } MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; } friend ostream& operator<<(ostream& os, const MInt& n) { os<; template struct Matrix { int width, height; vector> v; Matrix(int w) : width(w), height(w), v(w, vector(w, 0)) {}; Matrix(int w, int h) : width(w), height(h), v(w, vector(h, 0)) {}; Matrix(vector> _v) : width(_v.size()), height(_v[0].size()), v(_v) {}; Matrix operator*(const Matrix& n) const { Matrix ans = v; return ans *= n; } Matrix& operator*=(const Matrix& rhs) { Matrix ans(height, rhs.width); for (int i = 0; i < height; ++i) for (int j = 0; j < rhs.width; ++j) for (int k = 0; k < width; ++k) ans[i][j] += v[i][k] * rhs.v[k][j]; width = rhs.width; v = ans.v; return *this; } Matrix pow(ll N) { Matrix pow = *this, ans(width); for (int i = 0; i < width; ++i) ans[i][i] = 1; for (ll p = N; p > 0; p >>= 1, pow *= pow) if (p & 1) ans *= pow; return ans; } vector& operator[](int i) { return v[i]; } }; int main() { int N; cin >> N; Matrix m(4); m.v[0][0] = m.v[0][1] = m.v[0][2] = m.v[0][3] = 1; m.v[1][0] = m.v[2][1] = m.v[3][2] = 1; rep(i, N) { ll a; cin >> a; if (a <= 4) { cout << a / 4 << endl; continue; } Matrix p(4, 1); p[0][0] = 1; cout << (m.pow(a-4) * p)[0][0] << endl; } return 0; }