import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int Q = scanner.nextInt(); Q scanner.nextInt() scanner.nextInt scanner String S = scanner.next(); S scanner.next() scanner.next scanner int[] array = new int[S.length()]; array new int[S.length()] S.length() S.length S for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        } int i=1; int i=1; i 1 i<S.length() i S.length() S.length S i++ i++ i {
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        } {
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        } if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            } S.charAt(i) == 'C' && S.charAt(i-1) == 'A' S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' S.charAt(i-1) == 'A' S.charAt(i-1) S.charAt S i-1 i 1 'A' {
                array[i] = array[i-1] + 1;
            } array[i] = array[i-1] + 1 array[i] array i array[i-1] + 1 array[i-1] array i-1 i 1 1 {
                array[i] = array[i-1];
            } array[i] = array[i-1] array[i] array i array[i-1] array i-1 i 1 for(int i=0; i<Q; i++){
            int l = scanner.nextInt();
            l--;
            int r = scanner.nextInt();
            r--;
            System.out.println(array[r] - array[l]);
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            int l = scanner.nextInt();
            l--;
            int r = scanner.nextInt();
            r--;
            System.out.println(array[r] - array[l]);
        } {
            int l = scanner.nextInt();
            l--;
            int r = scanner.nextInt();
            r--;
            System.out.println(array[r] - array[l]);
        } int l = scanner.nextInt(); l scanner.nextInt() scanner.nextInt scanner l-- l int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner r-- r System.out.println(array[r] - array[l]) System.out.println System.out System System.out array[r] - array[l] array[r] array r array[l] array l String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

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

    }
}
