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

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

ull abakus(ull 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::vector<ull> asd;
	std::vector<ull> temp = ulaz;
	std::sort(temp.begin(), temp.end());

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

		if (temp[l] == i)
		{
			asd.push_back(m.size());
			l++;
		}
	}

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