using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Abakus
{
    internal class Program
    {
        static int IzracunajN(int n) {
            HashSet<int> rezultati = new HashSet<int>();
            int rezultat = 1;
            for (int i = 1; i <= n; i++)
            {
                rezultat = 1;
                int current = i;
                while (current != 0 && rezultat != 0)
                {
                    rezultat *= current % 10;
                    current = current / 10;
                }
                rezultati.Add(rezultat);
            }

            return rezultati.Count;
        }
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());

            int[] inputs = new int[T];

            for (int i = 0; i < T; i++)
            {
                inputs[i] = int.Parse(Console.ReadLine());
            }

            for (int i = 0;i < T; i++)
            {
                Console.WriteLine(IzracunajN(inputs[i]));
            }

          
        }
    }
}