#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
main(){
cin>>t;
while(t--){
int n;
cin>>n;
if(n<=10)cout<<n<<endl;
else{
    map<ll,bool> m;
    for(int i=0;i<n;i++){
        m[i]=false;
    }
    for(int i=1;i<=n;i++){
        int x=i;
        ll br=1;
      //  if(x<=10)br=x;
        while(x>=1){
            br*=(x%10);
            x/=10;
        }
      //  cout<<i<<" "<<br<<endl;
        m[br]=true;
    }
    int br1=0;
    for(auto it:m){
        if(it.second==true)br1++;
        //cout<<it.first<<" "<<it.second<<endl;
    }
    cout<<br1<<endl;
}

}


}