#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll MOD=mod;
ll sum(ll A, ll B)
{
A = (A + MOD) % MOD;
B = (B + MOD) % MOD;
ll ans = (A + B) % MOD;
ans = (ans + MOD) % MOD;
return ans;
}
ll f(ll a, ll n)
{
ll res = a, ans = 0;
while (n)
{
if (n % 2)
ans = (ans + res) % MOD;
res = (res + res) % MOD;
n /= 2;
}
return ans;
}
struct matran
{
ll a[4][4];
void print()
{
for (ll i = 0; i < 4; i++)
{
for (ll j = 0; j < 4; j++)
cout << a[i][j] << " ";
cout << '\n';
}
}
};
matran mot, M;
struct matran_1
{
ll a[1][4];
void print()
{
for (ll i = 0; i < 1; i++)
{
for (ll j = 0; j < 4; j++)
cout << a[i][j] << " ";
cout << '\n';
}
}
};
matran prod(matran A, matran B)
{
matran C;
for (ll i = 0; i < 4; i++)
for (ll j = 0; j < 4; j++)
C.a[i][j] = 0;
for (ll i = 0; i < 4; i++)
{
for (ll j = 0; j < 4; j++)
{
for (ll k = 0; k < 4; k++)
C.a[i][j] = sum(C.a[i][j], f(A.a[i][k], B.a[k][j]));
}
}
return C;
}
matran_1 prod1(matran_1 A, matran B)
{
matran_1 C;
for (ll i = 0; i < 1; i++)
for (ll j = 0; j < 4; j++)
C.a[i][j] = 0;
for (ll i = 0; i < 1; i++)
for (ll j = 0; j < 4; j++)
for (ll k = 0; k < 4; k++)
C.a[i][j] = sum(C.a[i][j], f(A.a[i][k], B.a[k][j]));
return C;
}
matran po(matran A, ll n)
{
matran res = A, ans = mot;
while(n){
if(n%2) ans = prod(ans,res);
res = prod(res,res);
n/=2;
}
return ans;
}
int main()
{
ll unit[4][4] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
ll MM[4][4] = {{4, 0, 0, 0}, {1, 3, 1, 0}, {0, 2, 0, 0}, {2, 0, 0, 1}};
for (ll i = 0; i < 4; i++)
{
for (ll j = 0; j < 4; j++)
{
mot.a[i][j] = unit[i][j];
M.a[i][j] = MM[i][j];
}
}
ll tmp[1][4] = {{1, 1, 1, 1}};
matran_1 initi;
for (ll i = 0; i < 1; i++)
{
for (ll j = 0; j < 4; j++)
initi.a[i][j] = tmp[i][j];
}
ll testcase;
cin>>testcase;
while(testcase--){
ll nn;
cin>>nn;
matran_1 lala = prod1(initi,po(M,nn));
cout<<lala.a[0][0]<<'\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKbGwgTU9EPW1vZDsKbGwgc3VtKGxsIEEsIGxsIEIpCnsKICAgICAgICBBID0gKEEgKyBNT0QpICUgTU9EOwogICAgICAgIEIgPSAoQiArIE1PRCkgJSBNT0Q7CiAgICAgICAgbGwgYW5zID0gKEEgKyBCKSAlIE1PRDsKICAgICAgICBhbnMgPSAoYW5zICsgTU9EKSAlIE1PRDsKICAgICAgICByZXR1cm4gYW5zOwp9CmxsIGYobGwgYSwgbGwgbikKewogICAgICAgIGxsIHJlcyA9IGEsIGFucyA9IDA7CiAgICAgICAgd2hpbGUgKG4pCiAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKG4gJSAyKQogICAgICAgICAgICAgICAgICAgICAgICBhbnMgPSAoYW5zICsgcmVzKSAlIE1PRDsKICAgICAgICAgICAgICAgIHJlcyA9IChyZXMgKyByZXMpICUgTU9EOwogICAgICAgICAgICAgICAgbiAvPSAyOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYW5zOwp9CnN0cnVjdCBtYXRyYW4KewogICAgICAgIGxsIGFbNF1bNF07CiAgICAgICAgdm9pZCBwcmludCgpCiAgICAgICAgewogICAgICAgICAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IDQ7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IGFbaV1bal0gPDwgIiAiOwogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICdcbic7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQp9OwptYXRyYW4gbW90LCBNOwpzdHJ1Y3QgbWF0cmFuXzEKewogICAgICAgIGxsIGFbMV1bNF07CiAgICAgICAgdm9pZCBwcmludCgpCiAgICAgICAgewogICAgICAgICAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IDE7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IGFbaV1bal0gPDwgIiAiOwogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICdcbic7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQp9OwptYXRyYW4gcHJvZChtYXRyYW4gQSwgbWF0cmFuIEIpCnsKICAgICAgICBtYXRyYW4gQzsKICAgICAgICBmb3IgKGxsIGkgPSAwOyBpIDwgNDsgaSsrKQogICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgICAgICAgICAgQy5hW2ldW2pdID0gMDsKICAgICAgICBmb3IgKGxsIGkgPSAwOyBpIDwgNDsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgICAgIGZvciAobGwgaiA9IDA7IGogPCA0OyBqKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGwgayA9IDA7IGsgPCA0OyBrKyspCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQy5hW2ldW2pdID0gc3VtKEMuYVtpXVtqXSwgZihBLmFbaV1ba10sIEIuYVtrXVtqXSkpOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQzsKfQptYXRyYW5fMSBwcm9kMShtYXRyYW5fMSBBLCBtYXRyYW4gQikKewogICAgICAgIG1hdHJhbl8xIEM7CiAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IDE7IGkrKykKICAgICAgICAgICAgICAgIGZvciAobGwgaiA9IDA7IGogPCA0OyBqKyspCiAgICAgICAgICAgICAgICAgICAgICAgIEMuYVtpXVtqXSA9IDA7CiAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IDE7IGkrKykKICAgICAgICAgICAgICAgIGZvciAobGwgaiA9IDA7IGogPCA0OyBqKyspCiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGwgayA9IDA7IGsgPCA0OyBrKyspCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQy5hW2ldW2pdID0gc3VtKEMuYVtpXVtqXSwgZihBLmFbaV1ba10sIEIuYVtrXVtqXSkpOwogICAgICAgIHJldHVybiBDOwp9Cm1hdHJhbiBwbyhtYXRyYW4gQSwgbGwgbikKewogICAgICAgIG1hdHJhbiByZXMgPSBBLCBhbnMgPSBtb3Q7CiAgICAgICAgd2hpbGUobil7CiAgICAgICAgICAgICAgICBpZihuJTIpIGFucyA9IHByb2QoYW5zLHJlcyk7CiAgICAgICAgICAgICAgICByZXMgPSBwcm9kKHJlcyxyZXMpOwogICAgICAgICAgICAgICAgbi89MjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFuczsKfQppbnQgbWFpbigpCnsKCQogICAgICAgIGxsIHVuaXRbNF1bNF0gPSB7ezEsIDAsIDAsIDB9LCB7MCwgMSwgMCwgMH0sIHswLCAwLCAxLCAwfSwgezAsIDAsIDAsIDF9fTsKICAgICAgICBsbCBNTVs0XVs0XSA9IHt7NCwgMCwgMCwgMH0sIHsxLCAzLCAxLCAwfSwgezAsIDIsIDAsIDB9LCB7MiwgMCwgMCwgMX19OwogICAgICAgIAogICAgICAgIGZvciAobGwgaSA9IDA7IGkgPCA0OyBpKyspCiAgICAgICAgewogICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgbW90LmFbaV1bal0gPSB1bml0W2ldW2pdOwogICAgICAgICAgICAgICAgICAgICAgICBNLmFbaV1bal0gPSBNTVtpXVtqXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGwgdG1wWzFdWzRdID0ge3sxLCAxLCAxLCAxfX07CiAgICAgICAgbWF0cmFuXzEgaW5pdGk7CiAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IDE7IGkrKykKICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGxsIGogPSAwOyBqIDwgNDsgaisrKQogICAgICAgICAgICAgICAgICAgICAgICBpbml0aS5hW2ldW2pdID0gdG1wW2ldW2pdOwogICAgICAgIH0KICAgICAgICBsbCB0ZXN0Y2FzZTsKICAgICAgICBjaW4+PnRlc3RjYXNlOwogICAgICAgIHdoaWxlKHRlc3RjYXNlLS0pewogICAgICAgICAgICAgICAgbGwgbm47CiAgICAgICAgICAgICAgICBjaW4+Pm5uOwogICAgICAgICAgICAgICAgbWF0cmFuXzEgbGFsYSA9IHByb2QxKGluaXRpLHBvKE0sbm4pKTsKICAgICAgICAgICAgICAgIGNvdXQ8PGxhbGEuYVswXVswXTw8J1xuJzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIDA7Cn0K