#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
const int N = 2e5+10;
const int MOD = 1e9 + 7;
using namespace std;



void solve()
{
    ll n,m;
    cin >> n;
    //vector<ll> a(n);
    //for(int i = 0; i < n; i++)cin>>a[i];


    vector<ll> mp(2*n, 0);
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll x = i;
        ll ans = 1;
        while(x > 0 ){
            ans *= x%10;
            x/=10;
        }
        mp[ans]++;
    }
    for(int i = 0; i < 2*n; i++){
        if(mp[i]!= 0)ans++;
    }
    cout << ans << "\n";





}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    cin >> t;

    while(t--){
        solve();
    }

}