#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int proizvod(int n)
{
    int p=1;
    while(n>0 && p>0)
    {
        p*=n%10;
        n/=10;
    }
    return p;
}
vector<int> a = {0,1,2,3,4,5,6,7,8,9};

void sadrzi(int x)
{
    for (int i=0;i<a.size();i++)
        if (x==a[i])
            return;
    a.push_back(x);
}

int main()
{
    int t;
    cin>>t;
    for (int i=0;i<t;i++)
    {
        int n;
        cin>>n;
        a = {0,1,2,3,4,5,6,7,8,9};
        if (n<21){
            cout<<min(n,10)<<'\n';
            continue;
        }
        for(int j=21;j<=n;j++)
        {
            sadrzi(proizvod(j));
        }
        cout<<a.size()<<'\n';
    }
}