import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    }

} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] s1 = sc.nextLine().split(" "); s1 sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int N = Integer.parseInt(s1[0]); N Integer.parseInt(s1[0]) Integer.parseInt Integer s1[0] s1 0 int Q = Integer.parseInt(s1[1]); Q Integer.parseInt(s1[1]) Integer.parseInt Integer s1[1] s1 1 String S = sc.nextLine(); S sc.nextLine() sc.nextLine sc StringBuilder sb = new StringBuilder(); sb new StringBuilder() int ss = 0; ss 0 int[] s = new int[N + 1]; s new int[N + 1] N + 1 N 1 for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        } {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        } if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            } i - 2 < 0 i - 2 i 2 0 {
                sb.append("");
            } sb.append("") sb.append sb "" {
                sb.append(S.charAt(i - 2));
            } sb.append(S.charAt(i - 2)) sb.append sb S.charAt(i - 2) S.charAt S i - 2 i 2 sb.append(S.charAt(i - 1)) sb.append sb S.charAt(i - 1) S.charAt S i - 1 i 1 if (sb.toString().equals("AC")) {
                ss++;
            } sb.toString().equals("AC") sb.toString().equals sb.toString() sb.toString sb "AC" {
                ss++;
            } ss++ ss s[i] = ss s[i] s i ss sb.setLength(0) sb.setLength sb 0 for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(s[r] - s[l]) System.out.println System.out System System.out s[r] - s[l] s[r] s r s[l] s l sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    }

} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    }

} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int N = Integer.parseInt(s1[0]);
        int Q = Integer.parseInt(s1[1]);
        String S = sc.nextLine();

        // a[]の生成

        StringBuilder sb = new StringBuilder();

        int ss = 0;
        int[] s = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            if (i - 2 < 0) {
                sb.append("");
            } else {
                sb.append(S.charAt(i - 2));
            }
            sb.append(S.charAt(i - 1));

            if (sb.toString().equals("AC")) {
                ss++;
            }
            s[i] = ss;
            sb.setLength(0);
        }

        // queryの処理
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(s[r] - s[l]);
        }

        sc.close();
    }

}
