namespace _3_
{
    internal class Program
    {
        static int podelibr(int n)
        {
            char[] a = n.ToString().ToCharArray();
            int[] j = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                j[i]=a[i];
            }
            int g = 1;
            for (int i = 0; i < a.Length; i++)
            {
                g = g + j[i];
            }
            return g;
        }
        
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            int[] res = new int[T];
            for (int i = 0; i < T; i++)
            {
                int n = int.Parse(Console.ReadLine());
                List<int> u = new List<int>();
                for (int j = 1; j <= n; j++)
                {
                    u.Add(podelibr(j));
                }
                for (int k = 0; k < u.Count;)
                {
                    int l = u[0];
                    while (u.Contains(l))
                        u.Remove(l);
                    res[i]++;
                }
            }
            foreach (int l in res)
            {
                Console.WriteLine(l);
            }
        }
    }
}