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

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < t; i++)
            {
                long n =Convert.ToInt64(Console.ReadLine());
                
                Dictionary<long , long>brojac=new Dictionary<long , long>();
                long tr = 1;
                for (int j = 1; j <= n; j++)
                 {
                    long k = j;
                    while (k > 0) 
                    {
                        tr *= k;
                        k = k / 10;
                    }
                    if (!brojac.ContainsKey(tr)) brojac[tr] = 1;

                }
                Console.WriteLine(brojac.Count);
            }
        }
    }
}