#include <bits/stdc++.h>

using namespace std;
#define endl "\n"

vector<pair<int, int>> testcases;
unordered_map<int, int> resenja;
unordered_map<int, bool> uniques;

int last_i = 0;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T; cin >> T;

    for (int i = 0 ; i<T; i++)
    {
        int inp; cin >> inp;
        testcases.push_back(pair<int,int>(inp, i));
    }
    sort(testcases.begin(), testcases.end());

    for (pair<int, int> asdads : testcases)
    {
        int n = asdads.first;
        int rbe = asdads.second;

        int i = last_i;
        for (; i < n; i++)
        {
            int p = 1;
            int br = i + 1;
            while (br != 0)
            {
                if (p == 0) break;
                p *= br % 10;
                br /= 10;
            }
            uniques[p] = true;
        }
        last_i = i;
        resenja[rbe] = uniques.size();
    }

    for (int i = 0; i < T; i++)
    {
        cout << resenja[i] << endl;
    }
    return 0;
}