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 = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        }

    }
}
 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 = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        }

    }
} 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 = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        }

    } CGeTAC public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        } solve {
            int n = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        } 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 p[] = new int[n]; p new int[n] n char a[] = s.toCharArray(); a s.toCharArray() s.toCharArray s if (a[0] == 'A' && a[1] == 'C') p[0] = 1; a[0] == 'A' && a[1] == 'C' a[0] == 'A' a[0] a 0 'A' a[1] == 'C' a[1] a 1 'C' p[0] = 1 p[0] p 0 1 for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            } {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            } if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                } a[i] == 'A' && a[i + 1] == 'C' a[i] == 'A' a[i] a i 'A' a[i + 1] == 'C' a[i + 1] a i + 1 i 1 'C' {
                    p[i] = p[i - 1] + 1;
                } p[i] = p[i - 1] + 1 p[i] p i p[i - 1] + 1 p[i - 1] p i - 1 i 1 1 {
                    p[i] = p[i - 1];
                } p[i] = p[i - 1] p[i] p i p[i - 1] p i - 1 i 1 p[n - 1] = p[n - 2] p[n - 1] p n - 1 n 1 p[n - 2] p n - 2 n 2 int ans = 0; ans 0 for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            } {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            } int l = in.nextInt(); l in.nextInt() in.nextInt in int r = in.nextInt(); r in.nextInt() in.nextInt in l-- l r-- r if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                } l == 0 l 0 {
                    ans = p[r - 1];
                } ans = p[r - 1] ans p[r - 1] p r - 1 r 1 {
                    ans = p[r - 1] - p[l - 1];
                } ans = p[r - 1] - p[l - 1] ans p[r - 1] - p[l - 1] p[r - 1] p r - 1 r 1 p[l - 1] p l - 1 l 1 out.println(ans) out.println out ans 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 = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        }

    }
} 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 = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        }

    }
} 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 = in.nextInt();
            int q = in.nextInt();
            String s = in.next();

            int p[] = new int[n];
            char a[] = s.toCharArray();
            if (a[0] == 'A' && a[1] == 'C') p[0] = 1;
            for (int i = 1; i < n - 1; i++) {
                if (a[i] == 'A' && a[i + 1] == 'C') {
                    p[i] = p[i - 1] + 1;
                } else {
                    p[i] = p[i - 1];
                }
            }
            p[n - 1] = p[n - 2];
            int ans = 0;
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                l--;
                r--;
                if (l == 0) {
                    ans = p[r - 1];
                } else {
                    ans = p[r - 1] - p[l - 1];
                }
                out.println(ans);
            }
        }

    }
}

