#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
typedef long long ll;
vector<unordered_map<ll, bool>> hshmps;

unordered_map<ll, bool> findhshmp(ll n)
{
    ll lhshmp = -1;
    for (ll i = 0; i < hshmps.size(); i++)
    {
        if (hshmps[i].size() > n)
        {
            if (lhshmp == -1)
            {
                unordered_map<ll, bool> ase;
                ase[0] = true;
                return ase;
            }
            return hshmps[lhshmp];
        }
        lhshmp = i;
    }
    unordered_map<ll, bool> ase;
    ase[0] = true;
    return ase;
}
void solve()
{
    ll n; cin >> n;

    unordered_map<ll, bool> fhshmp = findhshmp(n);
    if (fhshmp[0] == true)
    {
        unordered_map<ll, bool> brojevi;
        for (ll i = 1; i <= n; i++)
        {
            ll p = 1;

            ll br = i;
            while (br != 0)
            {
                p *= br % 10;
                br /= 10;
            }
            brojevi[p] = true;
        }
        hshmps.push_back(brojevi);
        cout << brojevi.size() << endl;
    }
    else {
        for (ll i = fhshmp.size(); i <= n; i++)
        {
            ll p = 1;

            ll br = i;
            while (br != 0)
            {
                p *= br % 10;
                br /= 10;
            }
            fhshmp[p] = true;
        }
        hshmps.push_back(fhshmp);
        cout << fhshmp.size() << endl;
    }
}

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

    while (T--) solve();
    return 0;
}