import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

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

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt(), Q = in.nextInt();
            String S = in.next();

            int ac[] = new int[N];

            int cnt = 0;
            char prev = 'Q';
            for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            }

            for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.OutputStream; OutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt(), Q = in.nextInt();
            String S = in.next();

            int ac[] = new int[N];

            int cnt = 0;
            char prev = 'Q';
            for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            }

            for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        }
    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) Task solver = new Task(); solver new Task() solver.solve(in, out) solver.solve solver in out out.close() out.close out String[] args args static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt(), Q = in.nextInt();
            String S = in.next();

            int ac[] = new int[N];

            int cnt = 0;
            char prev = 'Q';
            for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            }

            for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            }
        }
    } Task void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt(), Q = in.nextInt();
            String S = in.next();

            int ac[] = new int[N];

            int cnt = 0;
            char prev = 'Q';
            for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            }

            for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            }
        } solve {
            int N = in.nextInt(), Q = in.nextInt();
            String S = in.next();

            int ac[] = new int[N];

            int cnt = 0;
            char prev = 'Q';
            for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            }

            for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            }
        } int N = in.nextInt() N in.nextInt() in.nextInt in Q = in.nextInt(); Q in.nextInt() in.nextInt in String S = in.next(); S in.next() in.next in int ac[] = new int[N]; ac new int[N] N int cnt = 0; cnt 0 char prev = 'Q'; prev 'Q' for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            } int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            } {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            } if (prev == 'A' && S.charAt(i) == 'C') ++cnt; prev == 'A' && S.charAt(i) == 'C' prev == 'A' prev 'A' S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' ++cnt cnt ac[i] = cnt ac[i] ac i cnt prev = S.charAt(i) prev S.charAt(i) S.charAt S i for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            } int i = 0; int i = 0; i 0 i < Q i Q ++i ++i i {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            } {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            } int l = in.nextInt() - 1 l in.nextInt() - 1 in.nextInt() in.nextInt in 1 r = in.nextInt() - 1; r in.nextInt() - 1 in.nextInt() in.nextInt in 1 int ans = ac[r]; ans ac[r] ac r if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                } l > 0 l 0 {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                } ans -= ac[l - 1] ans ac[l - 1] ac l - 1 l 1 if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans; S.charAt(l - 1) == 'A' && S.charAt(l) == 'C' S.charAt(l - 1) == 'A' S.charAt(l - 1) S.charAt S l - 1 l 1 'A' S.charAt(l) == 'C' S.charAt(l) S.charAt S l 'C' --ans ans out.println(ans) out.println out ans InputReader in in PrintWriter out out static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        }
    } InputReader BufferedReader reader; reader StringTokenizer tokenizer; tokenizer InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        } InputReader {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(stream)) reader new BufferedReader(new InputStreamReader(stream)) tokenizer = null tokenizer null InputStream stream stream String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer int nextInt() { return Integer.parseInt(next()); } nextInt { return Integer.parseInt(next()); } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        } nextIntArray {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        } int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < n; ++i) arr[i] = this.nextInt(); int i = 0; int i = 0; i 0 i < n i n ++i ++i i arr[i] = this.nextInt(); arr[i] = this.nextInt() arr[i] arr i this.nextInt() this.nextInt this return arr; arr int n n
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

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

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt(), Q = in.nextInt();
            String S = in.next();

            int ac[] = new int[N];

            int cnt = 0;
            char prev = 'Q';
            for (int i = 0; i < N; ++i) {
                if (prev == 'A' && S.charAt(i) == 'C') ++cnt;
                ac[i] = cnt;
                prev = S.charAt(i);
            }

            for (int i = 0; i < Q; ++i) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int ans = ac[r];
                if (l > 0) {
                    ans -= ac[l - 1];
                    if (S.charAt(l - 1) == 'A' && S.charAt(l) == 'C') --ans;
                }
                out.println(ans);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        }
    }
}
