import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int Q = Integer.parseInt(sc.next()); Q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String S = sc.next(); S sc.next() sc.next sc int[] t = new int[N]; t new int[N] N int l = 0; l 0 int r = 0; r 0 int result = 0; result 0 int count = 0; count 0 t[0] = 0 t[0] t 0 0 for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        } {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        } if (S.substring(i, i + 2).equals("AC")) {
                count++;
            } S.substring(i, i + 2).equals("AC") S.substring(i, i + 2).equals S.substring(i, i + 2) S.substring S i i + 2 i 2 "AC" {
                count++;
            } count++ count t[i + 1] = count t[i + 1] t i + 1 i 1 count PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        } {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        } l = Integer.parseInt(sc.next()) l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc result = t[r - 1] - t[l - 1] result t[r - 1] - t[l - 1] t[r - 1] t r - 1 r 1 t[l - 1] t l - 1 l 1 out.println(result) out.println out result out.flush() out.flush out 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 = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    }
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] t = new int[N];
        int l = 0;
        int r = 0;
        int result = 0;
        int count = 0;

        t[0] = 0;
        for (int i = 0; i < N - 1; i++) {
            if (S.substring(i, i + 2).equals("AC")) {
                count++;
            }
            t[i + 1] = count;
        }

        PrintWriter out = new PrintWriter(System.out);
        for (int i = 0; i < Q; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            result = t[r - 1] - t[l - 1];
            out.println(result);
            out.flush();
        }
        sc.close();
    }
}