using System;

namespace ConsoleApp1
{
    class Program
    {
        static long proizvodCifara(long a)
        {
            long br = 1;
            for(long i = a; i != 0; i /= 10)
            {
                br *= a % 10;
                a /= 10;
            }
            return br;
        }
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] a = new long[n];
            for(long i = 0; i <= n - 1; i++)
            {
                long x = long.Parse(Console.ReadLine());
                long br = 0;
                long[] b = new long[x];
                long y = x;
                while (y > 0)
                {
                    b[y - 1] = proizvodCifara(y);
                    y--;
                }
                for(long j = x - 1; j >= 0; j--)
                {
                    long c = 0;
                    for (long k = j - 1; k >= 0; k--)
                    {
                        if (b[j] == b[k])
                        {
                            c = 1;
                            break;
                        }
                    }
                    if (c == 0)
                    {
                        br++;
                    }
                }
                a[i] = br;
            }
            for(long i = 0; i <= n - 1; i++)
            {
                Console.WriteLine(a[i]);
            }
        }
    }
}