#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main()
{
    int t, x ;
    cin >> t;
    vector<unsigned long long> niz(t);
    for(int i = 0; i < t; i++){
        cin >> niz[i];
    }

    for(int i = 0; i < t; i++){
        x = 0;
        vector<int> niz1;

        for(int j = 1; j <= niz[i]; j++){
            int br = j, br1 = 1;
            while(br > 0){
                br1 *= br % 10;
                br /= 10;
            }
            if(count(niz1.begin(), niz1.end(), br1) == 0){
                x++;
                niz1.push_back(br1);
            }
        }

        cout << x << endl;
    }

}