#include using namespace std; using ll = long long; using VV = vector >; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)< void vprint(T &V){ for(auto v : V){ cout << v << " "; } cout << endl; } // Matrix Library VV mat_mul(const VV& x, const VV& y){ int a = x.size(); int b = x[0].size(); int c = y[0].size(); VV z(a, vector(c, 0)); FOR(i, 0, a){ FOR(j, 0, c){ FOR(k, 0, b){ z[i][j] += x[i][k] * y[k][j]; z[i][j] %= mod; // 必要であれば } } } return z; } VV mat_pow(const VV& x, ll k){ int n = x.size(); VV y(n, vector(n, 0)); FOR(i, 0, n){ y[i][i] = 1; } VV z = x; if(k==0) return y; if(k==1) return z; if(k%2==0){ return mat_pow(mat_mul(x, x), k/2); }else{ return mat_mul(x, mat_pow(x, k-1)); } } void print_mat(VV x){ ll H = x.size(); FOR(i, 0, H){ vprint(x[i]); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll Q; cin >> Q; VV A ={ {1, 1, 1, 1}, {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, }; FOR(i, 0, Q){ ll n; cin >> n; auto B = mat_pow(A, n); ll ans = B[3][3]; p(ans); } return 0; }