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

using namespace std;

int main()
{
    int t, x = 0;
    cin >> t;
    vector<pair<unsigned long long, int>> niz(t);
    vector<unsigned long long> pr(t);
    vector<int> niz1;
    for(int i = 0; i < t; i++){
        cin >> niz[i].first;
        niz[i].second = i;
    }

    sort(niz.begin(), niz.end());

    for(int i = 1; i <= niz[0].first; i++){
        int br = i, br1 = 1;

        while(br > 0){
            br1 *= br % 10;
            br /= 10;
        }

        if(count(niz1.begin(), niz1.end(), br1) == 0){
            x++;
            niz1.push_back(br1);
        }
    }

    pr[niz[0].second] = x;

    for(int i = 1; i < t; i++){
        for(int j = niz[i - 1].first; j <= niz[i].first; j++){
            int br = j, br1 = 1;

            while(br > 0){
                br1 *= br % 10;
                br /= 10;
            }

            if(count(niz1.begin(), niz1.end(), br1) == 0){
                x++;
                niz1.push_back(br1);
            }
        }

        pr[niz[i].second] = x;
    }

    for(int i = 0; i < t; i++){
        cout << pr[i] << endl;
    }
}