import java.util.*;


public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    }
} import java.util.*; util.* java public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    }
} Main private static final int INF = 1000000007; INF 1000000007 private static final int INF1 = Integer.MAX_VALUE; INF1 Integer.MAX_VALUE Integer Integer.MAX_VALUE public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    } 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 String str = sc.next(); str sc.next() sc.next sc int[] array = new int[str.length()]; array new int[str.length()] str.length() str.length str for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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<str.length() i str.length() str.length str i++ i++ i {
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        } {
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        } if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            } str.charAt(i) == 'C' && str.charAt(i-1) == 'A' str.charAt(i) == 'C' str.charAt(i) str.charAt str i 'C' str.charAt(i-1) == 'A' str.charAt(i-1) str.charAt str 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 = sc.nextInt();
            --l;
            int r = sc.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        } {
            int l = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc --l l int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc --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 {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    }
} public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    }
} Main
import java.util.*;


public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

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

        for(int i=1; i<str.length(); i++){
            if(str.charAt(i) == 'C' && str.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 = sc.nextInt();
            --l;
            int r = sc.nextInt();
            --r;
            System.out.println(array[r] - array[l]);
        }

    }
}
