#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);

    int t; cin>>t;

    for (int i = 0; i < t; ++i){
        ll n;cin>>n;

        unordered_set<int> s;

        int res = 0;

        for (int j = 1; j <= n; ++j){
            int digits = 0;
            int mult = 1;
            int r = j;

            while (pow(10LL, digits) <= j)
                ++digits;

            for (int k = 0; k < digits; ++k){
                int digit = r % 10;
                r/=10;
                mult *= digit;
            }

            if (s.find(mult) == s.end()){
                ++res;
                s.insert(mult);
            }
        }

        cout<<res<<'\n';
    }

    return 0;
}