#include <iostream>
#include <set>
#include <vector>
using namespace std;

int proizvod_cifara(int x) {
    int p = 1;
    while (x > 0) {
        int c = x % 10;
        p *= c;
        x /= 10;
    }
    return p;
}

int main() {
    int T;
    cin >> T;
    vector<int> ulazi(T);
    for (int i = 0; i < T; i++) {
        cin >> ulazi[i];
    }

    for (int n : ulazi) {
        set<int> razliciti;
        for (int i = 1; i <= n; i++) {
            int p = proizvod_cifara(i);
            razliciti.insert(p);
        }
        cout << razliciti.size() << "\n";
    }

    return 0;
}