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);
        GetAC solver = new GetAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class GetAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[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);
        GetAC solver = new GetAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class GetAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[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);
        GetAC solver = new GetAC();
        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);
        GetAC solver = new GetAC();
        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) GetAC solver = new GetAC(); solver new GetAC() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class GetAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            }

        }

    } GetAC public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            }

        } solve {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            }

        } int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in char[] s = in.next().toCharArray(); s in.next().toCharArray() in.next().toCharArray in.next() in.next in int[] dp = new int[n]; dp new int[n] n for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            } {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            } if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                } s[i] == 'A' && s[i + 1] == 'C' s[i] == 'A' s[i] s i 'A' s[i + 1] == 'C' s[i + 1] s i + 1 i 1 'C' {
                    dp[i + 1] = dp[i] + 1;
                } dp[i + 1] = dp[i] + 1 dp[i + 1] dp i + 1 i 1 dp[i] + 1 dp[i] dp i 1 {
                    dp[i + 1] = dp[i];
                } dp[i + 1] = dp[i] dp[i + 1] dp i + 1 i 1 dp[i] dp i for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            } {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            } int l = in.nextInt() - 1; l in.nextInt() - 1 in.nextInt() in.nextInt in 1 int r = in.nextInt() - 1; r in.nextInt() - 1 in.nextInt() in.nextInt in 1 out.println(dp[r] - dp[l]) out.println out dp[r] - dp[l] dp[r] dp r dp[l] dp 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);
        GetAC solver = new GetAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class GetAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[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);
        GetAC solver = new GetAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class GetAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[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);
        GetAC solver = new GetAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class GetAC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] dp = new int[n];

            for (int i = 0; i < n - 1; i++) {
                if (s[i] == 'A' && s[i + 1] == 'C') {
                    dp[i + 1] = dp[i] + 1;
                } else {
                    dp[i + 1] = dp[i];
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                out.println(dp[r] - dp[l]);
            }

        }

    }
}

