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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            long[] a = new long[t];
            long p = 1;
            for (int i = 0; i<t; i++)
            {
                long n = long.Parse(Console.ReadLine());
                long br = 1;
                List<long> b = new List<long>();
                while (br <= n)
                {
                    long br2 = br;
                    while (br > 0)
                    {
                        p *= br % 10;
                        br /= 10;
                    }
                    if (!b.Contains(p))
                        b.Add(p);
                    br = br2;
                    br++;
                }
                a[i] = b.Count();
            }
            for (int i = 0; i<t; i++)
            {
                Console.WriteLine(a[i]);
            }

            
        }
    }
}