#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;

int main() {
    int T;

    cin >> T;

    vector<long long> n(T);

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

    for (int i = 0; i < T; i++) {
        int rezultati = 0;

        set<long long> s = {};

        for (int j = 1; j <= n[i]; j++) {
            int temp = j;
            int broj = 1;

            while (temp != 0) {
                int cifra = temp % 10;
                broj *= cifra;
                temp /= 10;
            }



            s.insert(broj);
        }

        cout << s.size() << endl;
    }

    return 0;
}