using System;

    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            s.Replace("a", "1");
            s.Replace("b", "2");
            s.Replace("c", "3");
            int c = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < c; i++)
            {
                string[] w = Console.ReadLine().Split(" ");
                Console.WriteLine(A(s.Substring(Convert.ToInt32(w[0])-1, Convert.ToInt32(w[1])+1 - Convert.ToInt32(w[0]))));                                         //[Convert.ToInt32(w[0]:Convert.ToInt32(w[1]))
            }
        }
        static int A(string w)
        {
            int c = 0;
            for(int i =0;i<w.Length-1;i++)
            {
                if ((int)w[i] > (int)w[i + 1])
                {
                    c++;
                }
            }
            return c+1;
        }
    }

