#include <bits/stdc++.h>

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

ll last_i = 0;
void solve()
{
    ll n; cin >> n;

    for (ll i = last_i ; i <= n; i++)
    {
        ll p = 1;

        ll br = i;
        while (br != 0)
        {
            p *= br % 10;
            br /= 10;
        }
        brojevi[p] = true;

    }
    cout << brojevi.size() << endl;
    last_i = n;
}

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

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