import java.util.Scanner;
//a  b  c  a  a  b  b  a  c  c  c  c  b
//ab bc ca aa ab bb ba ac cc cc cc cb
//      +           +              +
//1  2  3  4  5  6  7  8  9  10 11 12 13
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int q = in.nextInt();
        System.out.println("");
        int[][] arr = new int[q][2];
        for (int i=0; i<q; i++){
            arr[i][0]=in.nextInt();
            arr[i][1]=in.nextInt();
//            System.out.println(arr[i][0]+"   "+arr[i][1]);
        }
        char[] numb= s.toCharArray();
/////        int[] numb=new int[s.length()];
/*        for (int i=0; i<s.length(); i++){
            if(c[i]=='a'){
                numb[i]=1;
            }else{if(c[i]=='b'){
                numb[i]=2;
            }else{numb[i]=3;}}
        }*/
        int t= s.length()-1;
        int[] a= new int[s.length()-1];
        for(int i=0; i<t; i++){
            a[i]=numb[i]-numb[i+1];
//            System.out.println(a[i]);
        }
        for(int i=0; i<q; i++){
///////////////////////

        int index = 1;
        int aa = arr[i][0]-1;
        int b = arr[i][1]-1;
        for(int j=aa; j<b; j++){
            if(a[j]>0){
                index++;
            }
        }
        System.out.println(index);
/////////////////////////
        }
 //       int[] r = new int[q];
/*        for(int i=0; i<q; i++){
///////////////////////

        int index = -2;
        int t = arr[i][0]-1;
        int tm = arr[i][1]-2;
        while (t!=-1||t<tm){
            t = s.indexOf("ab", t);
            index++;
        }
        t=arr[i][0]-1;
        while (t!=-1||t<tm){
            t = s.indexOf("ac", t);
            index++;
        }
        t=arr[i][0]-1;
        while (t!=-1||t<tm){
            t = s.indexOf("bc", t);
            index++;
        }
        System.out.println(index);
/////////////////////////
        }*/
    }
}
