import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) CGeTAC solver = new CGeTAC(); solver new CGeTAC() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class CGeTAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        }

    } CGeTAC public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        } solve {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        } int n = Integer.parseInt(in.next()); n Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int q = Integer.parseInt(in.next()); q Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in String S = in.next(); S in.next() in.next in int[] s = new int[n + 1]; s new int[n + 1] n + 1 n 1 for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            } {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            } if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i]; i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C' i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C' i + 1 < n i + 1 i 1 n 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' s[i + 1] = s[i] + 1 s[i + 1] s i + 1 i 1 s[i] + 1 s[i] s i 1 s[i + 1] = s[i] s[i + 1] s i + 1 i 1 s[i] s i for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            } {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            } int l = Integer.parseInt(in.next()); l Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int r = Integer.parseInt(in.next()); r Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in --l l --r r out.println(s[r] - s[l]) out.println out s[r] - s[l] s[r] s r s[l] s l int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            String S = in.next();

            // 出力
            int[] s = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (i + 1 < n && S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') s[i + 1] = s[i] + 1;
                else s[i + 1] = s[i];
            }
            for (int i = 0; i < q; i++) {
                int l = Integer.parseInt(in.next());
                int r = Integer.parseInt(in.next());
                --l;
                --r;
                out.println(s[r] - s[l]);

            }

        }

    }
}

