#include using namespace std; using ll = long long; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) // Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac #define dump(var) do{std::cerr << #var << " : ";view(var);}while(0) template void view(T e){std::cerr << e << "\n";} template void view(const std::vector& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";} template void view(const std::vector >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } } template void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); } namespace mm { template using matrix = std::vector>; template matrix E(int n) { matrix res(n, std::vector(n, 0)); for(int i = 0; i < n; i++) res[i][i] = 1; return res; } template matrix matMul(matrix a, matrix b) { assert(a.size() && b.size()); assert(a[0].size() == b.size()); matrix res(a.size(), std::vector(b[0].size(), 0)); for(int i = 0; i < a.size(); i++) { for(int j = 0; j < b[0].size(); j++) { for(int k = 0; k < b.size(); k++) { res[i][j] += a[i][k] * b[k][j]; } } } return res; } template std::vector vecMul(matrix a, std::vector b) { assert(a.size() && b.size()); assert(a[0].size() == b.size()); std::vector res(b.size(), 0); for(int i = 0; i < a.size(); i++) { for(int j = 0; j < b.size(); j++) { res[i] += a[i][j] * b[j]; } } return res; } template matrix matPow(matrix a, long long p) { assert(a.size() && a.size() == a[0].size()); matrix res(a.size(), std::vector(a.size(), 0)); for(int i = 0; i < a.size(); i++) res[i][i] = 1; while(p) { if(p & 1) res = matMul(res, a); a = matMul(a, a); p /= 2; } return res; } } using namespace mm; #include using mint = atcoder::modint1000000007; void solve() { ll n; cin >> n; mint v = mint(3).inv(); matrix M = { {v, 0, 0, 0, v, v}, {0, v, 0, v, 0, v}, {0, 0, v, v, v, 0}, {1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0} }; vector V = {v, 0, 0, 1, 0, 0}; auto RM = matPow(M, n); auto RV = vecMul(RM, V); cout << RV[3].val() << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll t; cin >> t; while(t--) solve(); return 0; }