#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
int T;
LL n;
struct Matrix{
LL h[5][5];
}a;
int main(){
ios::sync_with_stdio(false);
cin>>T;
while(T--){
Matrix ans,t;
cin>>n;
ans.h[1][1]=1; ans.h[1][2]=1; ans.h[1][3]=1;
t.h[1][1]=1; t.h[1][2]=1; t.h[1][3]=0;
t.h[2][1]=0; t.h[2][2]=0; t.h[2][3]=1;
t.h[3][1]=1; t.h[3][2]=0; t.h[3][3]=0;
for(n-=3;n>0;n>>=1){
if(n&1){
Matrix x;
for(int i=1;i<=3;i++){
LL sum=0;
for(int j=1;j<=3;j++)sum+=ans.h[1][j]*t.h[j][i],sum%=mod;
x.h[1][i]=sum;
}
for(int i=1;i<=3;i++)ans.h[1][i]=x.h[1][i];
}
Matrix d;
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++){
LL sum=0;
for(int k=1;k<=3;k++)sum+=t.h[i][k]*t.h[k][j],sum%=mod;
d.h[i][j]=sum;
}
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)t.h[i][j]=d.h[i][j];
}
cout<<ans.h[1][1]<<endl;
}
return 0;
}
//结构体函数版:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
int T;
LL n;
struct Matrix{
LL h[5][5];
void clear(){
memset(h,0,sizeof(h));
}
Matrix operator * (const Matrix& t) const{
Matrix d; d.clear();
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++){
LL sum=0;
for(int k=1;k<=3;k++)sum+=h[i][k]*t.h[k][j],sum%=mod;
d.h[i][j]=sum;
}
return d;
}
Matrix operator ^ (LL k) const {
Matrix ans(*this),t(*this),x(*this);
t.clear();
t.h[1][1]=1; t.h[1][2]=1; t.h[1][3]=0;
t.h[2][1]=0; t.h[2][2]=0; t.h[2][3]=1;
t.h[3][1]=1; t.h[3][2]=0; t.h[3][3]=0;
for(k-=3;k>0;k>>=1){
if(k&1)
for(int i=1;i<=3;i++){
LL sum=0;
for(int j=1;j<=3;j++)sum+=ans.h[1][j]*t.h[j][i],sum%=mod;
x.h[1][i]=sum;
}
for(int i=1;i<=3;i++)ans.h[1][i]=x.h[1][i];
t=t*t;
}
return ans;
}
}a;
int main(){
ios::sync_with_stdio(false);
cin>>T;
while(T--){
Matrix ans,t;
cin>>n;
ans.h[1][1]=1; ans.h[1][2]=1; ans.h[1][3]=1;
t.h[1][1]=1; t.h[1][2]=1; t.h[1][3]=0;
t.h[2][1]=0; t.h[2][2]=0; t.h[2][3]=1;
t.h[3][1]=1; t.h[3][2]=0; t.h[3][3]=0;
ans=ans^n;
cout<<ans.h[1][1]<<endl;
}
return 0;
}