namespace _3_
{
    internal class Program
    {
        static long podelibr(long n)
        {
            char[] a = n.ToString().ToCharArray();
            long[] j = new long[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                j[i]=a[i];
            }
            long g = 1;
            if (j.Contains(48)||j.Contains(49))
            {
                return 0;
            }
            for (int i = 0; i < a.Length; i++)
            {
                g = g * (j[i]-48);
            }
            return g;
        }
        
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            int[] res = new int[T];
            for (int i = 0; i < T; i++)
            {
                long n = int.Parse(Console.ReadLine());
                List<long> u = new List<long>();
                for (long j = 1; j <= n; j++)
                {
                    u.Add(podelibr(j));
                }
                for (int k = 0; k < u.Count;)
                {
                    long l = u[0];
                    while (u.Contains(l))
                        u.Remove(l);
                    res[i]++;
                }
            }
            foreach (int l in res)
            {
                Console.WriteLine(l);
            }
        }
    }
}