#include<bits/stdc++.h>

using namespace std;

int main() {

int t;cin>>t;
vector<int>ress(t);
for(int g=0;g<t;g++){
	int n;
cin>>n;
	vector<int>br(0);

for(int i=1;i<n+1;i++){
	int ib=1;
	int f=i;
while(f>1){
	
	int c=f%10;
	f/=10;
	ib*=c;
	
}
br.push_back(ib);	
}
int res=n;
sort(br.begin(),br.end());
//cout<<br.size();
for(int a=1;a<br.size();a++){
if(br[a-1]==br[a])res--;	
//	cout<<br[a]<<" ";
	
}
ress[g]=res;	
	
}


for(int j=0;j<t;j++){
	cout<<ress[j]<<endl;
}

}