#include<bits/stdc++.h>
using namespace std;
long long n,a;
long long rez,br;
map <long long,long long> mapa;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    while(n--){
        cin>>a;
        if(a <= 100000){
        for(int i = 1; i <= a; i++){
        if(i >= 10000 and i <= 99999){
            rez = (i/10000)*(i%10000/1000)*(i%1000/100)*(i%100/10)*(i%10);
            mapa[rez] = 1;
        }
        else if(i >= 1000 and i <= 9999){
            rez = (i/1000)*(i % 1000 / 100) * (i%100/10) * (i%10);
            mapa[rez] = 1;
        }
        else if(i >= 100 and i <= 999){
            rez = (i / 100) * (i%100/10) * (i%10);
            mapa[rez] = 1;
        }
        else if(i >= 10 and i <= 99){
            rez = (i/10)*(i%10);
            mapa[rez] = 1;
        }
        else{
            rez = i%10;
            mapa[rez] = 1;
            }
        }
    }
    else{
        cout<<a<<"\n";
        continue;
    }
    for(map<long long,long long>::iterator it=mapa.begin(); it!=mapa.end();it++){
        if(it->second == 1) br++;
        }
        cout<<br<<"\n";
        br = 0;
        mapa.clear();
    }

    return 0;
}