#include<iostream>
#include<vector>
#include<unordered_map>

typedef unsigned long long ull;
std::unordered_map<ull, bool> m;

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

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

	m[resenje] = true;
	return resenje;
}

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

	ull maks = 0;

	std::unordered_map<ull, bool> upiti;
	std::vector<ull> ulaz(t);

	for (int i = 0; i < t; i++)
	{
		std::cin >> ulaz[i];

		upiti[ulaz[i]] = true;

		if (ulaz[i] > maks)
			maks = ulaz[i];
	}

	std::unordered_map<int, ull> resenja;

	for (int i = 1; i <= maks; i++)
	{
		abakus(i);

		if (upiti[i])
			resenja[i] = m.size();
	}

	for (int i = 0; i < ulaz.size(); i++)
	{
		std::cout << resenja[ulaz[i]] << '\n';
	}
}