#include <bits/stdc++.h>

using namespace std;

int funkcija (int n) {
    int br1 = 1;
    int br2;
    int s;
    vector<int> v1;
    for (int i = 1; i <= n; i++) {
        br1 = 1;
        s = i;
        while (s > 0) {
            br2 = s % 10;
            br1 *= br2;
            s /= 10;
        }
        if (binary_search(v1.begin(), v1.end(), br1) == false) {
            v1.push_back(br1);
        }
    }
    return v1.size();
}

int main()
{
    int n, x; vector<int> v1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x;
        v1.push_back(x);
    }
    for (int i = 0; i < v1.size(); i++) {
        cout << funkcija(v1[i]) << '\n';
    }
}