import java.util.*;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc char[] qc = sc.next().toCharArray(); qc sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int data[] = new int[n+1]; data new int[n+1] n+1 n 1 for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        } int i = 1; int i = 1; i 1 i<n i n i++ i++ i {
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        } {
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        } data[i] = data[i-1] data[i] data i data[i-1] data i-1 i 1 if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            } qc[i] == 'C' qc[i] qc i 'C' {
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            } if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                } qc[i-1] == 'A' qc[i-1] qc i-1 i 1 'A' {
                    data[i] = data[i-1] + 1;
                } data[i] = data[i-1] + 1 data[i] data i data[i-1] + 1 data[i-1] data i-1 i 1 1 int l[] = new int[q]; l new int[q] q int r[] = new int[q]; r new int[q] q for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i<q i q i++ i++ i {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        } int i = 0; int i = 0; i 0 i<q i q i++ i++ i {
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        } {
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        } System.out.println(data[r[i]-1] - data[l[i]-1]) System.out.println System.out System System.out data[r[i]-1] - data[l[i]-1] data[r[i]-1] data r[i]-1 r[i] r i 1 data[l[i]-1] data l[i]-1 l[i] l i 1 String[] args args public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    }
} Main
import java.util.*;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    }
}