using System;
using System.Collections.Generic;
using System.Text;

public class Program
{
    static HashSet<long> racun(long n)
    {
        var nums = new List<int>();
        long temp = n;
        while (temp > 0)
        {
            nums.Add((int)(temp % 10));
            temp /= 10;
        }
        nums.Reverse();
        var rec = new Dictionary<(int, bool, bool, long), HashSet<long>>();
        HashSet<long> DP(int pos, bool sad, bool pocetna, long x)
        {
            var key = (pos, sad, pocetna, x);
            if (rec.ContainsKey(key)) return rec[key];
            if (pos == nums.Count)
            {
                if (pocetna) return new HashSet<long> { x };
                else return new HashSet<long>();
            }
            var res = new HashSet<long>();
            int max;
            if (sad)
            {
                max = nums[pos];
            }
            else
            {
                max = 9;
            }

            for (int d = 0; d <= max; d++)
            {
                bool nextsad = sad && (d == max);
                bool nextpocetna = pocetna || d != 0;
                long sledeca;
                if (pocetna)
                {
                    sledeca = x * d;
                }
                else
                {
                    sledeca = d;
                }

                if (!nextpocetna) sledeca = 1;
                res.UnionWith(DP(pos + 1, nextsad, nextpocetna, sledeca));
            }
            rec[key] = res;
            return res;
        }
        return DP(0, true, false, 1);
    }

    public static void Main(string[] args)
    {
        int T = int.Parse(Console.ReadLine());
        for (int t = 0; t < T; t++)
        {
            /*
            bool nextsad = sad && (d == max);
            bool nextpocetna = pocetna || d != 0;
            long sledeca;
             */
            long n = long.Parse(Console.ReadLine());
            var temp2 = racun(n);
            Console.WriteLine(temp2.Count);
        }
    }
}