#include <iostream>

using namespace std;

int main()
{
    int t,b=1,o,br=1,br2=0;
    cin>>t;
    int n[t];
    for (int i=0;i<t;i++){
        cin>>n[i];
    }
    for (int i=0;i<t;i++){
        int niz[200000];
        br2=0;
         for (int j=0;j<n[i];j++){
            //cout<<j+1<<e
            o=j+1;
            b=1;
            br=1;
            while(o!=0){
                b*=(o%10);
                o=o/10;
            }
            niz[0]=0;
            for(int x=0;x<br;x++){
                if(niz[x]!=b){
                    niz[x+1]=b;
                    br2++;
                }
            }
        }
        cout<<br2+1<<endl;
    }


    return 0;
}