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 sum = 1;
        int numb = scanner.nextInt();
        int [] sumArr = new int[numb];
        for(int i=0; i<numb;i++){
            sum=1;
            int r = scanner.nextInt()-1;
            int l = scanner.nextInt()-1;
            for (int j = r; j < l; j++) {
                if(charArray[j]=='b'&charArray[j+1]=='a'){
                    sum+=1;
                }else if(charArray[j]=='c'&(charArray[j+1]=='a'||charArray[j+1]=='b')){
                    sum+=1;
                }
            }
            sumArr[i]=sum;
        }
        for (int i = 0; i < numb; i++) {
            System.out.println(sumArr[i]);
        }
    }
}
