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


string s = Console.ReadLine();
int q = int.Parse(Console.ReadLine());

int split(int a, int b)
{
    List<string> words = new List<string>();
    string word = "";
    char tmp = char.MinValue;

    for (int i = a - 1; i < b; i++)
    {
        if (s[i] == 'a' && (tmp == 'b' || tmp == 'c'))
        {
            words.Add(word);
            word = s[i].ToString();
            tmp = s[i];
        }
        else if (s[i] == 'b' && tmp == 'c')
        {
            words.Add(word);
            word = s[i].ToString();
            tmp = s[i];
        }
        else
        {
            word += s[i];
            tmp = s[i];
        }
    }

    words.Add(word);

    return words.Count;
}


List<int[]> arr = new List<int[]>();
for (int i = 0; i < q; i++)
{
    string lr = Console.ReadLine();
    int[] tmp = lr.Split(' ').Select(int.Parse).ToArray();
    arr.Add(tmp);
}
foreach (int[] a in arr)
{
    Console.WriteLine(split(a[0], a[1]));
}