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

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

                }
           

            }
        }
    }