import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    } main {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer N = sc.nextInt(); N sc.nextInt() sc.nextInt sc Integer Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc Integer[] l = new Integer[Q] l new Integer[Q] Q r = new Integer[Q]; r new Integer[Q] Q for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int[] a = new int[N]; a new int[N] N int count = 0; count 0 for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        } {
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        } if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            } S.charAt(i-1) == 'A' && S.charAt(i) == 'C' S.charAt(i-1) == 'A' S.charAt(i-1) S.charAt S i-1 i 1 'A' S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' {
                count++;
                a[i] = count;
            } count++ count a[i] = count a[i] a i count {
                a[i] = count;
            } a[i] = count a[i] a i count for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        } {
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        } System.out.println(a[r[i]-1] - a[l[i]-1]) System.out.println System.out System System.out a[r[i]-1] - a[l[i]-1] a[r[i]-1] a r[i]-1 r[i] r i 1 a[l[i]-1] a 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);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        Integer Q = sc.nextInt();
        String S = sc.next();

        Integer[] l = new Integer[Q], r = new Integer[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int[] a = new int[N];
        int count = 0;
        for(int i = 1; i < N; i++){
            if(S.charAt(i-1) == 'A' && S.charAt(i) == 'C'){
                count++;
                a[i] = count;
            } else {
                a[i] = count;
            }
        }

        for(int i = 0; i < Q; i++){
            System.out.println(a[r[i]-1] - a[l[i]-1]);
        }

    }
}