#include <bits/stdc++.h>

using namespace std;
#define endl "\n"

void solve()
{
    int n; cin >> n;

    unordered_map<int, bool> brojevi;
    for (int i = 1; i <= n; i++)
    {
        int p = 1;

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

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

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