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

int main() {
    int broj;
    cin >> broj;

    vector <long long> lista(10000000000, 0);
    vector <long long> pre;

    int resenje = 0;

    for (long long x=1; x <= 10000000000; x++) {
        long long temp = x;
        long long counter = 1;
        int nasao = 0;

        while (temp > 0){
            counter *= temp % 10;
            temp /= 10;
        }

        for (int y=0; y < pre.size(); y++) {
            if (counter == pre[y]) {
                nasao = 1;
                break;
            }
        }

        if (nasao == 0) {
            resenje += 1;
            pre.push_back(counter);
        }

        lista[x] = resenje;
    }



    for (int q=0; q < broj; q++) {
        long long ulaz;
        cin >> ulaz;

        if (ulaz == 1) {
            cout << 1 << "\n";
        }

        else {
            cout << lista[ulaz+1] << "\n";
        }

    }


    return 0;
}