int T = int.Parse(Console.ReadLine());
int key = 0;
Queue<int> q = new Queue<int>();
for (int i = 0; i < T; i++)
{
    int br = int.Parse(Console.ReadLine());
    int pom = br;
    int cif;
    Dictionary<int, int> dic = new Dictionary<int, int>();
    for (int j = 1; j <= pom; j++)
    {
        int k = j;
        int zbrC = 1;
        while (k > 0) 
        {
            zbrC *= (k%10);
            k /= 10;
        }
        key++;
        if (!dic.ContainsValue(zbrC)) { dic.Add(key, zbrC); }
    }
    q.Enqueue(dic.Count);
}
for (int i = 0;i < T; i++) Console.WriteLine(q.Dequeue());