#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll proizcif(ll br){
    ll proiz=1;
    while(br>0){
        proiz*=br%10;
        br/=10;
    }
    return proiz;
}


int main(){
    ll t;
    cin >> t;
    for (int test=0; test<t; test++){
        ll n,br=0;
        cin >> n;
        unordered_map<ll,bool> c;
        for (int i=1; i<=n; i++){
            /*ll pr=proizcif(i);
            if (c[pr]!=true){
                br++;
                c[pr]=true;
            }*/
        }
        cout << br << endl;
    }
    return 0;
}