#include <bits/stdc++.h>

#define ll long long

void solve()
{
    ll n, j, br;
    std::set<ll> cnt;

    std::cin >> n;

    for(ll i = 0; i < n; i++)
    {
        ll r = 1;
        std::string s = std::to_string(i);
        for(char c : s)
            r *= c - '0';
        cnt.insert(r);
    }

    std::cout << cnt.size() << "\n";
}

int main()
{
    int t;
    std::cin >> t;
    
    while(t--)
        solve();

    return 0;
}