#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 T;
	vector<long long> N;
	vector<long long> niz;
	vector<long> proizvodi;
	cin>>T;
	for(long i=0;i<T;i++){
		long a;
		cin>>a;
		N.push_back(a);
	}
	for(long i=0;i<T;i++){
		long long n = N[i];
		while(n>0){
			niz.push_back(suma(n));
			n--;
		}
		skloni(niz);
		proizvodi.push_back(niz.size());	
		niz.clear();
	}
		for (long i=0;i<proizvodi.size();i++) {
        cout << proizvodi[i] << endl;
    }
}