#include <bits/stdc++.h>

using namespace std;

int broj_cifara(long long int n) {
    int br = 0;
    if(n != 0) {
        while(n != 0) {
            br++;
            n /= 10;
        }
    }else if (n = 0) br = 1;
    return br;
}

long long int proizvod_cifara(long long int n) {
    long long int pr = 1;
    for(int i = 0; i < broj_cifara(n); ++i) {
        if(n / (long long int)pow(10, i) == 0) {
            pr = 0;
            return pr;
        }
        pr *= (n / (long long int)pow(10, i)) % 10;
    }return pr;
}



int main()
{
    int t;
    cin >> t;
    long long int n[t];
    for(int i = 0; i < t; ++i) {
        cin >> n[i];
    }for(int i = 0; i < t; ++i) {
        vector<long long int> a = {1};
        for(int j = 1; j <= n[i]; ++j) {
            int pom = 0;
            for(int k = 0; k < a.size(); ++k) {
                if(a[k] != proizvod_cifara(j)) {
                    pom++;
                }
            }if(pom == a.size()) a.push_back(proizvod_cifara(n[i]));
        }cout << a.size() << "\n";
    }return 0;
}