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

}