#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vec; typedef vector mat; ll N, K; ll MOD = 1'000'000'007; ll mod_pow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } ll mod_inverse(ll x, ll mod = MOD) { return mod_pow(x, mod - 2, mod); } 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]) % MOD; } } } 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; } ll _A[6][6] = { {1, 0, 0, 0, 1, 1}, {0, 1, 0, 1, 0, 1}, {0, 0, 1, 1, 1, 0}, {3, 0, 0, 0, 0, 0}, {0, 3, 0, 0, 0, 0}, {0, 0, 3, 0, 0, 0}, }; ll _B[6][1] = { {1}, {0}, {0}, {3}, {0}, {0}, }; int main() { int T; cin >> T; mat A(6); for (int i = 0; i < 6; ++i) { vector row; for (int j = 0; j < 6; ++j) { row.push_back(_A[i][j]); } A[i] = row; } mat B(6); for (int i = 0; i < 6; ++i) { B[i].push_back(_B[i][0]); } for (int i = 0; i < T; ++i){ int N; cin >> N; mat C = pow(A, N); ll m = mod_inverse(mod_pow(3, N + 1, MOD)); mat D = mul(C, B); cout << (m * D[3][0]) % MOD << endl; } return 0; }