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[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

        sc.close();
    }

} 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[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

        sc.close();
    }

} 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[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

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

        int[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

        sc.close();
    } 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[] pos = new int[n]; pos new int[n] n for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        } {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        } if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            } s.charAt(i) == 'A' && s.charAt(i + 1) == 'C' s.charAt(i) == 'A' s.charAt(i) s.charAt s i 'A' s.charAt(i + 1) == 'C' s.charAt(i + 1) s.charAt s i + 1 i 1 'C' {
                pos[i] = 1;
            } pos[i] = 1 pos[i] pos i 1 int[] num = new int[n]; num new int[n] n num[0] = pos[0] num[0] num 0 pos[0] pos 0 for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        } {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        } num[i] = num[i - 1] + pos[i] num[i] num i num[i - 1] + pos[i] num[i - 1] num i - 1 i 1 pos[i] pos i for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int max; max if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            } r - 1 - 1 < 0 r - 1 - 1 r - 1 - 1 r 1 1 0 {
                max = 0;
            } max = 0 max 0 {
                max = num[r - 1 - 1];
            } max = num[r - 1 - 1] max num[r - 1 - 1] num r - 1 - 1 r - 1 - 1 r 1 1 int min; min if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            } l - 1 - 1 < 0 l - 1 - 1 l - 1 - 1 l 1 1 0 {
                min = 0;
            } min = 0 min 0 {
                min = num[l - 1 - 1];
            } min = num[l - 1 - 1] min num[l - 1 - 1] num l - 1 - 1 l - 1 - 1 l 1 1 int ans = max - min; ans max - min max min System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc 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[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

        sc.close();
    }

} 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[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

        sc.close();
    }

} 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[] pos = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                pos[i] = 1;
            }
//            System.out.println("pos:" + pos[i]);
        }

        int[] num = new int[n];
        num[0] = pos[0];
        for (int i = 1; i < n - 1; i++) {
            num[i] = num[i - 1] + pos[i];
//            System.out.println(num[i]);
        }
//        System.out.println();

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int max;
            if (r - 1 - 1 < 0) {
                max = 0;
            } else {
                max = num[r - 1 - 1];
            }
            int min;
            if (l - 1 - 1 < 0) {
                min = 0;
            } else {
                min = num[l - 1 - 1];
            }
            int ans = max - min;
            System.out.println(ans);
        }

        sc.close();
    }

}
