#include <bits/stdc++.h>
using namespace std;

int set2(int a){
    int res = 1;
    while(a!=0){
        res*=a%10;
        a/=10;
    }
  //  cout << res << endl;
    return res;
}
int main(){
    int t, n;
    cin >> t;
    while(t--){
        set<int> s;
        cin >> n;

        for(int i = 1; i<=n; i++){
            s.insert(set2(i));
        }
        cout << s.size() << endl;
    }
    return 0;
}