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

int t, tpm[200005];

bitset<INT_MAX> a;

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 = 0;

        cin >> n;

        a.reset();

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

        tpm[tp] = br;
    }

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

    return 0;
}