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

namespace ConsoleApp1
{
    class Program
    {
        static int cif(int n)
        {
            int[] a = new int[n];
            int br = 1;
            a[0] = 1;
            for (int i = 1; i <= n; i++)
            {
                int pr = 1;
                int c = 1;
                while (c > 0)
                {
                    c = i % 10;
                    pr *= c;
                }
                if (pr > a[a.Length - 1] || bp(a, a[a.Length - 1], pr))
                {
                    br++;
                }
            }
            return br;
        }
        static bool bp(int[] a, int d, int x)
        {
            int l = 1;
            while (l < d)
            {
                int mid = (l + d) / 2;
                if (x == mid) return true;
                else if (x > mid) l = mid;
                else d = mid;
            }
            return false;
        }
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());

            while (t > 0)
            {
                int n = int.Parse(Console.ReadLine());

                if(n<=10)
                {
                    Console.WriteLine(n);
                    continue;
                }

                int br = cif(n);
                Console.WriteLine(br);

                t--;
            }
        }
    }
}