#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    int t;
    vector<int>v1(t);
    cin>>t;
    for(int f=0;f<t;f++)
    {
    cin>>n;
    int cifra;
    int br1=0;
    vector<int>v(n);
    int s=1;
    int br2=1;
    for(int i=1;i<n+1;i++)
    {    br2=i;
         s=1;
         while(br2>0)
            {
            cifra=br2%10;
            s=s*cifra;
            br2=br2/10;
            }
         v.push_back(s);
    }
    sort(v.begin(),v.end());
    for(int i=1;i<v.size();i++)
        if(v[i-1]==v[i])
           br1++;
    int p=v.size()-br1;
    v.clear();
    v1.push_back(p);
    }
    for(int u=0;u<t;u++)
        if(v1[u]<10)
            cout<<v1[u]-1<<endl;
        else
            cout<<v1[u]<<endl;
    v1.clear();


 return 0;
}