#include <iostream>
#include <vector>

using namespace std;
int proizvod(int br)
{
    int pr=1;
    while(br>0)
    {
        pr=pr*(br%10);
        br=br/10;
    }
    return pr;
}
bool dalisurazliciti(vector<int> s, int j)
{
    for(int m=1; m<j; m++)
    {
        if(s[m]==s[j])
        return false;

    }
    return true;
}

int main()
{
    int t, k=0, br;
    bool tacnost;
    cin>>t;
    vector<int> v;
    vector<int> s;
    for(int i=1; i<=t; i++)
    {
        cin>>v[i];
        for(int j=1; j<=v[i]; j++)
        {
            br=j;
            s[j]=proizvod(br);
            tacnost=dalisurazliciti(s, j);
            if(tacnost=true) k++;
        }
        cout<<k;
        k=0;
    }
    return 0;
}