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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        long long n;
        cin >> n;
        set<long long> razliciti;
        for (long long i = 1; i <= n; i++) {
            long long p = proizvod_cifara(i);
            razliciti.insert(p);
        }
        cout << razliciti.size() << "\n";
    }
    return 0;
}