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

public class A2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split("");
        int q = sc.nextInt();
        int n = 0;
        StringBuilder ns = new StringBuilder();
//        List<Integer> o = new ArrayList<>(0);

        for (int i = 0; i <q; i++) {
            n=0;
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l==r-1){
                if (s[l].equals("b")){
                    if (s[r].equals("a")) System.out.println("2");;
                }
                if (s[l].equals("c")){
                    if (s[r].equals("a") || s[r].equals("b")) System.out.println("2");;
                }
            }
            for (int j = l; j < r-1; j++) {
                if (s[j].equals("b")){
                    if (s[j+1].equals("a"))n++;
                }
                if (s[j].equals("c")){
                    if (s[j+1].equals("a") || s[j+1].equals("b")) n++;
                }
            }
            //o.add(n+1);
            ns.append((n + 1)).append("\n");
        }
//        for (Integer integer : o) {
//            System.out.println(integer);
//        }
        System.out.println(ns);
    }
}
