#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int suma(long n){
	int suma=1;
	while(n>0){
		suma = n%10 * suma;
		n=n/10;
		if(suma == 0)
		break;
		
	}
	return suma;
}
void skloni(vector<long long>& v){
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());	
}
int main()
{
	long long T,n=0,n1=0;
	vector<long long> niz;
	vector<long> proizvodi;
	cin>>T;
	for(long i=0;i<T;i++){
		cin>>n;
		while(n1<=n){
			niz.push_back(suma(n1));
			n1++;
		}
		n1--;
		skloni(niz);
		proizvodi.push_back(niz.size());	
	}
	for (long i=0;i<proizvodi.size();i++) {
        cout << proizvodi[i] << endl;
    }
}