namespace zadatakc
{
    internal class Program
    {
        static void Main(string[] args)
        {
            long n = int.Parse(Console.ReadLine());
                       
            for(long i = 1; i<=n;i++)
            {
                long p = 0;

                long x = int.Parse(Console.ReadLine());
                long s = 1;
                long[] niz = new long[x];
                long br = 0;
                for (long j = 1; j <= x; j++)
                {
                    long a = j;
                    while (a != 0)
                    {
                        p = a % 10;
                        s *= p;
                        a /= 10;
                    }
                    for (long k = 0; k < x; k++)
                    {
                        if (niz[k] == s)
                        {
                            break;
                        }
                        else
                        {
                            niz[0 + k] = s;
                            br++;
                            break;
                        }
                    }
                }
                 Console.WriteLine(br);

                }
           

            }
        }
    }