#include <bits/stdc++.h>
using namespace std;

int t, tpm[200005];
vector<bool> a;

unordered_map<int, int> dp;
int dpv = 0;

int mlc(int x) {
    int m = 1;
    while (x >= 1) {
        m *= x % 10;
        x /= 10;
    }
    return m;
}

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

    cin >> t;

    for (int tp = 0; tp < t; tp++) {
        int n, br = dp[dpv];
        unordered_map<int, bool> a;

        cin >> n;

        for (int i = dpv + 1; i <= n; i++) {
            int m = mlc(i);
            if (!a[m]) {
                a[m] = true;
                br++;
            }
        }

        dp[n] = br;
        dpv++;

        tpm[tp] = br;
    }

    for (int tp = 0; tp < t; tp++) cout << tpm[tp] << '\n';

    return 0;
}