#include<iostream>
#include<unordered_map>

typedef unsigned long long ull;

ull abakus(int br)
{
	ull resenje = 1;

	while (br > 0)
	{
		resenje *= br % 10;
		br /= 10;
		if (resenje == 0)
			break;
	}

	return resenje;
}

int main()
{
	int t = 0;
	std::cin >> t;

	for (int i = 0; i < t; i++)
	{
		ull br;
		std::cin >> br;

		std::unordered_map<ull, bool> m;

		for (ull j = 1; j <= br; j++)
			m[abakus(j)] = true;

		std::cout << m.size() << "\n";
	}
}