#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n; cin >> n;

        map<long long, bool> mapa; long long prod, cop = 1, sum = 0;
        for (int i = 1; i <= n; i++) {
            prod = 1; cop = i;
            while (cop > 0) {
                prod *= cop % 10;
                cop /= 10;
            }

            if (!mapa[prod]) sum++;
            mapa[prod] = true;
        }

        cout << sum << "\n";
    }

    return 0;
}