using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static int faktorizacija(int n)
        {
            int n2 = n;
            int suma = 1;
            while (n2 > 0)
            {
                suma = suma * n2 % 10;
                n2 /= 10;
            }
            return suma;
        }
        static void Main(string[] args)
        {   
            int T = int.Parse(Console.ReadLine());
            for (int u = 0; u < T; u++)
            {
                int n = int.Parse(Console.ReadLine());
                List<int> suma = new List<int>();
                for (int i=1;i<=n;i++)
                {
                    suma.Add(faktorizacija(i));
                }
                suma.Sort();            
                Console.WriteLine(suma.Count);   
                
            }

            
        }
    }
}