

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String s = sc.next();
        int[] arr = new int[s.length()];
        for(int i = 1; i < s.length(); i++) {
            if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A') {
                arr[i] = arr[i-1] + 1;
            } else {
                arr[i] = arr[i-1];
            }
        }

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

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

        for(int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            l--;
            r--;
            System.out.println(arr[r] - arr[l]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String s = sc.next();
        int[] arr = new int[s.length()];
        for(int i = 1; i < s.length(); i++) {
            if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A') {
                arr[i] = arr[i-1] + 1;
            } else {
                arr[i] = arr[i-1];
            }
        }

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

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

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


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String s = sc.next();
        int[] arr = new int[s.length()];
        for(int i = 1; i < s.length(); i++) {
            if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A') {
                arr[i] = arr[i-1] + 1;
            } else {
                arr[i] = arr[i-1];
            }
        }

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