#include <iostream>
#include <vector>

using namespace std;

long long pc(long long a){
    long long res = 1;
    for(; a != 0; a /= 10){
        int c = a % 10;
        res *= c;
        if(!res || c == 1) break;
    }
    return res;
}

int main()
{
    int T;
    cin >> T;
    long long N;
    while(T--){
        cin >> N;
        int res = 0;
        vector<bool> p(N + 1, false);
        for(long long i = 1; i < N + 1; i++){
            long long cur = pc(i);
            if(!p[cur]){
                res++;
                p[cur] = true;
            }
        }
        cout << res << '\n';
    }
}