using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static long razliciti(long n)
    {
        long brr = 10;
        List<long> bili = new List<long>();
        for (long i = 25; i <= n; i++)
        {
            if (i % 10 == 0) continue;
            long br = i; long pr = 1;
            while (br > 9)
            {
                pr *= br % 10;
                br /= 10;
            }
            pr *= br;
            if (pr >= 10 && !bili.Contains(pr)) brr++;
            bili.Add(pr);
        }
        return brr;
    }
    static void Main(string[] args)
    {
        long t = long.Parse(Console.ReadLine());
        for (long i = 0; i < t; i++)
        {
            long n = long.Parse(Console.ReadLine());
            if (n <= 10) Console.WriteLine(n);
            else if (n < 25) Console.WriteLine(10);
            else Console.WriteLine(razliciti(n));
        }
    }
}