/* Problem URL: https://codeforces.com/gym/105164/problem/B */ #include using namespace std; #define V vector #define rmin(a, b) a = min(a, b) #define rmax(a, b) a = max(a, b) #define rep(i, lim) for (int i = 0; i < (lim); i++) #define nrep(i, s, lim) for (int i = s; i < (lim); i++) #define repv(i, v) for (auto &i : (v)) #define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } #define sortv(v) sort(v.begin(), v.end()) #define all(v) (v).begin(), (v).end() using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using ll = long long; using vl = vector; using vvl = vector; using vvvl = vector; using vvvvl = vector; template auto operator<<(ostream &os, const vector &vec)->ostream& { os << vec[0]; for (size_t i = 1; i < vec.size(); i++) { os << ' ' << vec[i]; } os << '\n'; return os; } template auto operator>>(istream &is, vector &vec)->istream& { for (auto &i : vec) { is >> i; } return is; } template auto operator<<(ostream &os, const vector> &vec)->ostream& { for (auto &i : vec) { os << i[0]; for (size_t j = 1; j < i.size(); j++) { os << ' ' << i[j]; } os << '\n'; } return os; } template auto operator>>(istream &is, vector> &vec)->istream& { for (auto &i : vec) { for (auto &j : i) { is >> j; } } return is; } ll mod = 1e9 + 7; vvl operator*(vvl &a, vvl &b) { vvl ans(a.size(), vl(b[0].size())); rep(i, a.size()) { rep(j, b[0].size()) { rep(k, a[0].size()) { ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % mod; } } } return ans; } ll exp(int n) { vvl ans = { {1}, {0}, {0}, {0}, {0}, {3}, {0}, {0}, {0}, {3}, {0}, {9}, {0}, {3}, {0}, {18}, {0}, {30}, {0}, {27} }; if (n < 20) { ll total = 0; for (int i = 0; i <= n; i++) { total += ans[i][0]; total %= mod; } return total; } n -= 20; vvl tmp(20, vl(20)); rep(i, 19) { tmp[i][i + 1] = 1; } for (int j = 20 - 6; j >= 0; j -= 4) { tmp[19][j] = 3; } rep(i, 31) { if ((n >> i) & 1) { ans = tmp * ans; } tmp = tmp * tmp; } ll total = 0; rep(i, 20) { total += ans[i][0]; total %= mod; } return total; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; // vl dp(n + 1); // dp[0] = 1; // // for (int i = 1; i <= n; i++) { // for (int j = i - 6; j >= 0 && abs(i - j) <= 20; j -= 4) { // dp[i] += dp[j] * 3; // dp[i] %= mod; // } // } // // ll total = 0; // for (int i = max(n - 19, 0); i <= n; i++) { // total += dp[i]; // total %= mod; // } cout << exp(n) << '\n'; // cout << total << '\n'; } }