import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class Mova {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        char[] charArray = str.toCharArray();
        int numb = scanner.nextInt();
        int [] sum = new int[numb];
        List<Integer> rList = new ArrayList<>();
        List<Integer> lList = new ArrayList<>();
        for (int i = 0; i < str.length()-1; i++) {
            if ((charArray[i] == 'b' & charArray[i + 1] == 'a') || (charArray[i] == 'c' & (charArray[i + 1] == 'a' || charArray[i + 1] == 'b'))) {
                rList.add(i);
                lList.add(i + 1);
            }
        }
        for (int i = 0; i < numb; i++) {
            int r=scanner.nextInt()-1;
            int l=scanner.nextInt()-1;
            for (int j = 0; j < rList.size(); j++){
               if(r<=rList.get(j)&l>=lList.get(j)){
                   sum[i]+=1;
               }
            }
        }
        for (int i = 0; i < numb; i++) {
            System.out.println(sum[i]+1);
        }
    }
}

