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

using namespace std;

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

    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++) {
        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;

                if (!(cifra == 0 || cifra == 1)) {
                    broj *= cifra;
                    temp /= 10;
                } else {
                    temp /= 10;
                }
            }

            s.insert(broj);
        }

        int rezultat = s.size() + 1;

        cout << rezultat << "\n";
    }

    return 0;
}