#include <iostream>
#include <unordered_map>
#include <vector>
int main()
{
	int t;
	std::cin >> t;
	std::vector<int> v;
	for (int k = 0; k < t; k++) {
		int n;
		std::cin >> n;
		std::unordered_map<int, int> rez;
		for (int i = 1; i <= n; i++) {
			int p = 1;
			for (int 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;
	}
}