RT
#include <bits/stdc++.h>
using namespace std;
#define int long long
int cnt;
int h=12,m;
signed main()
{
int d;scanf("%lld",&d);
while (d--)
{
h=12;m=0;
cnt=0;
int t;scanf("%lld",&t);
for (int i=1;i<=t;i++)
{
m++;
if(m>=60) m=i%60,h++;
if(h==13) h%=12;
if(m>9)
{
if(h>9&&((h/10-h%10==h%10-m/10&&h%10-m/10==m/10-m%10)||(m%10-m/10==m/10-h%10&&m/10-h%10==h%10-h/10)))
{
cnt++;
// cout<<"op1->"<<h<<":"<<m<<endl;
// cout<<"1."<<h/10-h%10<<','<<h%10-m/10<<','<<m/10-m%10<<endl;
// cout<<"2."<<m%10-m/10<<','<<m/10-h%10<<','<<h%10-h/10<<endl;
// cout<<"----------------"<<endl;
}
if(h<=9&&((h-m/10==m/10-m%10)||(m%10-m/10==m/10-h)))
{
cnt++;
// cout<<"op2->"<<h<<":"<<m<<endl;
// cout<<"1."<<h-m/10<<','<<m/10-m%10<<endl;
// cout<<"2."<<m%10-m/10<<','<<m/10-h<<endl;
// cout<<"----------------"<<endl;
}
}
}
printf("%lld\n",cnt);
}
return 0;
}