#include <iostream>
#include <unordered_map>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n<=10){
		    cout<<n<<"\n";
		    continue;
		}
		unordered_map<long long,int> mp;
		for(int i=1;i<=n;i++){
			long long p=1;
			int num=i;
			while(num>1){
			    int digit=num%10;
				p*=num%10;
				num/=10;
			}
			mp[p]++;
		}
		cout<<(int)mp.size()<<"\n";
	}
	
}