using System.Text;
public class Program
{
    static HashSet<long> res = new HashSet<long>();

    public static void Main(string[] args)
    {

        int t = int.Parse(Console.ReadLine());
        while (t > 0)
        {
            string nStr = Console.ReadLine();
            long n = long.Parse(nStr);
            res.Clear();
            res.Add(0); 

            char[] s = nStr.ToCharArray();

            int ss = 37;
            Console.WriteLine(ss);
            break;

            Solve(s);

            Console.WriteLine(res.Count);
            //t--;
            t -= 1;
        }
    }
    static void Solve(char[] s)
    {
        var rec = new Dictionary<string, HashSet<long>>();
        var dobarset = radi(0, true, false, 1, s, rec);
        foreach (var p in dobarset) res.Add(p);
    }
    static HashSet<long> radi(int idx, bool manje, bool kren, long prod, char[] s, Dictionary<string, HashSet<long>> rec)
    {
        if (idx == s.Length)
        {
            var hs = new HashSet<long>();
            if (kren) hs.Add(prod);
            return hs;
        }

        string key = $"{idx}_{manje}_{kren}_{prod}";
        if (rec.ContainsKey(key)) return rec[key];
        var temp = new HashSet<long>();
        int limit;
        if (manje)
        {
            limit = 9;
        }
        else
        {
            limit = (s[idx] - '0');
        }

        for (int d = 0; d <= limit; d++)
        {
            bool sledecimanje = manje || (d < limit);
            bool krece = kren || (d > 0);
            long borca;
            if (krece)
            {
                borca = (prod * d);
            }
            else
            {
                borca = 1;
            }

            if (krece && d == 0)
            {
                res.Add(0);
                continue;
            }
            var subres = radi(idx + 1, sledecimanje, krece, borca, s, rec);
            foreach (var p in subres) temp.Add(p);
        }
        rec[key] = temp;
        return temp;
    }
}