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

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

    vector <long long> ulazi;

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

        ulazi.push_back(ulaz);

    }

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

    long long resenje = 0;

    for (long long x=1; x <= 1000000000; 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 p=0; p < broj; p++) {
        cout << lista[ulazi[p]] << "\n";
    }


    return 0;
}