#include<iostream>
using namespace std;
int a[730],b[730],c[730],d[740],e[740];
int n,jishuqi=0,t,he,ii;
int main()
{
cin>>n;
a[1]=1;
b[1]=2;
c[1]=d[1]=0;
for(int i=1;i<=720;i++)
{
int j=i%60;
ii=12+i/60;
if(ii>12) ii=ii%12;
a[i]=ii/10;
b[i]=ii%10;
c[i]=j/10;
d[i]=j%10;
}
for(int i=1;i<=720;i++)
{
if(a[i]==0)
if(c[i]-b[i]==d[i]-c[i]&&c[i]-b[i]>=0&&d[i]-c[i]>=0)
{
e[i]++;
jishuqi++;
}
else
if(b[i]-a[i]==c[i]-b[i]&&d[i]-c[i]==c[i]-b[i]&&d[i]-c[i]>=0&&c[i]-b[i]>=0&&b[i]-a[i]>=0)
{
e[i]++;
jishuqi++;
}
}
for(int i=1;i<=n;i++)
{
cin>>t;
for(int i=1;i<=t%720;i++)
he+=e[i];
int k=(t/720)*jishuqi+he;
cout<<k+1<<endl;
he=0;
}
return 0;
}