import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    } try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        } {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

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

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int Q = in.nextInt();
            String S = in.next();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++) {
                l[i] = in.nextInt() - 1;
                r[i] = in.nextInt() - 1;
            }

            boolean[] isAC = new boolean[N];
            for (int i = 1; i < N; i++) {
                if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                    isAC[i] = true;
                }
            }

            int[] count = new int[N];
            for (int i = 1; i < N; i++) {
                count[i] = (isAC[i] ? 1 : 0) + count[i - 1];
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(count[r[i]] - (l[i] - 1 < 0 ? 0 : count[l[i]]));
            }
        }
    }
}
