#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;
unsigned long long int pow(unsigned long long int a,unsigned long long int b){
unsigned long long int res=1;
while(b){
if(b&1)res=res*a;
a=a*a;
b/=2;
}
return res;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
unsigned long long int p=pow(3,n);
if(n>=3){
cout<<p-6<<endl;
}
else cout<<p<<endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBpbmY9MWU5Owp1bnNpZ25lZCBsb25nIGxvbmcgaW50IHBvdyh1bnNpZ25lZCBsb25nIGxvbmcgaW50IGEsdW5zaWduZWQgbG9uZyBsb25nIGludCBiKXsKICAgIHVuc2lnbmVkIGxvbmcgbG9uZyBpbnQgcmVzPTE7CiAgICB3aGlsZShiKXsKICAgICAgICBpZihiJjEpcmVzPXJlcyphOwogICAgICAgIGE9YSphOwogICAgICAgIGIvPTI7CiAgICB9CiAgICByZXR1cm4gcmVzOwp9CmludCBtYWluKCl7CiAgICBpbnQgdDsKICAgIGNpbj4+dDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgaW50IG47CiAgICAgICAgY2luPj5uOwogICAgICAgIHVuc2lnbmVkIGxvbmcgbG9uZyBpbnQgcD1wb3coMyxuKTsKICAgICAgICBpZihuPj0zKXsKICAgICAgICAgICAgY291dDw8cC02PDxlbmRsOwogICAgICAgIH0KICAgICAgICBlbHNlIGNvdXQ8PHA8PGVuZGw7CiAgICB9Cn0=