#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int age[41];
void dfs(int now,int year,int sum)
{
int i;
int s=0;
//
if(now==year+1) cout<<sum<<endl;
for(i=0;i<41;i++)
{
if(age[i]!=0)
{
age[i]++;
if(age[i]<=3) s++;
}
else break;
}
for(int j=i;j<i+s;j++)
{
age[j]++;
sum++;
}
dfs(now+1,year,sum);
}
int main()
{
int t;
cin>>t;
while(t--)
{
memset(age,0,sizeof(age));
int year;
age[0]=1;
//
cin>>year;
/
if(year==0) cout<<1<<endl;
else dfs(1,year,1);
}
return 0;
}
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int age[41];
void dfs(int now,int year,int sum)
{
int i;
int s=0;
//
if(now==year+1) cout<<sum<<endl;
for(i=0;i<41;i++)
{
if(age[i]!=0)
{
age[i]++;
if(age[i]<=3) s++;
}
else break;
}
for(int j=i;j<i+s;j++)
{
age[j]++;
sum++;
}
dfs(now+1,year,sum);
}
int main()
{
int t;
cin>>t;
while(t--)
{
memset(age,0,sizeof(age));
int year;
age[0]=1;
//
cin>>year;
/
if(year==0) cout<<1<<endl;
else dfs(1,year,1);
}
return 0;
}