#include <bits/stdc++.h>

using namespace std;

int mnoziCifre(int n) {
    int m = 1;
    while (n != 0) {
        m = m * (n % 10);
        n -= n % 10;
        n = n / 10;
    }
    return m;
}

bool MyContains(vector<int> nizic, int brojcic) {
    for (int i = 0; i < nizic.size(); i++) {
        if (nizic[i] == brojcic) return true;
    }
    return false;
}

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

    int T;
    cin >> T;

    vector<int> brojevi(T);
    vector<int> resenja(T);
    vector<int> mojmap;

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

    for (int i = 0; i < T; i++) {
        for (int j = 0; j < brojevi[i] + 1; j++) {
            if (!MyContains(mojmap, mnoziCifre(j))) {
                mojmap.push_back(mnoziCifre(j));
                resenja[i]++;
            }
        }
        mojmap.clear();
    }

    for (int i = 0; i < T; i++) {
        cout << resenja[i] << endl;
    }

}