#include <iostream>
#include <unordered_map>
#include <vector>
int main()
{
	int t;
	std::cin >> t;
	std::vector<long long> v;
	for (int k = 0; k < t; k++) {
		long long n;
		std::cin >> n;
		std::unordered_map<long long, int> rez;
		for (int i = 1; i <= n; i++) {
			long long p = 1;
			for (long long j = 10; j <= 10 * i; j *= 10) {
				p *= (i % j - i % (j / 10)) / (j / 10);
			}
			rez[p] = 1;
		}
		v.push_back(rez.size());
	}
	for (int x : v) {
		std::cout << x << std::endl;
	}
}