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

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::vector<ull> ulaz(t);

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

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

	std::unordered_map<int, ull> resenja;

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

		if (std::find(ulaz.begin(), ulaz.end(), i) != ulaz.end())
			resenja[i] = m.size();
	}

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