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

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

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

    int resenje = 0;

    for (int x=1; x <= 1000000000; x++) {
        int temp = x;
        int 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++) {
        int ulaz;
        cin >> ulaz;

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

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

    }


    return 0;
}