import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
} Main private static Scanner sc; sc public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    } main {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    } Main instance = new Main(); instance new Main() sc = instance.new Scanner() sc instance.new Scanner() instance instance instance.solve() instance.solve instance String[] args args private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } solve {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } Exception e {
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc String R = new StringBuffer(S).reverse().toString(); R new StringBuffer(S).reverse().toString() new StringBuffer(S).reverse().toString new StringBuffer(S).reverse() new StringBuffer(S).reverse new StringBuffer(S) int[] l = new int[S.length()]; l new int[S.length()] S.length() S.length S int[] r = new int[S.length()]; r new int[S.length()] S.length() S.length S Arrays.fill(l, 0) Arrays.fill Arrays l 0 Arrays.fill(r, 0) Arrays.fill Arrays r 0 int tmpl = 0; tmpl 0 int tmpr = 0; tmpr 0 for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            } int i = 1; int i = 1; i 1 i < S.length() i S.length() S.length S i++ i++ i {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            } {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            } l[i] = tmpl l[i] l i tmpl if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                } S.charAt(i-1) == 'A' && S.charAt(i) == 'C' S.charAt(i-1) == 'A' S.charAt(i-1) S.charAt S i-1 i 1 'A' S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' {
                    tmpl++;
                    l[i] = tmpl;
                } tmpl++ tmpl l[i] = tmpl l[i] l i tmpl r[i] = tmpr r[i] r i tmpr if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                } R.charAt(i-1) == 'C' && R.charAt(i) == 'A' R.charAt(i-1) == 'C' R.charAt(i-1) R.charAt R i-1 i 1 'C' R.charAt(i) == 'A' R.charAt(i) R.charAt R i 'A' {
                    tmpr++;
                    r[i] = tmpr;
                } tmpr++ tmpr r[i] = tmpr r[i] r i tmpr int a a b; b for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            } {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            } a = sc.nextInt() a sc.nextInt() sc.nextInt sc b = sc.nextInt() b sc.nextInt() sc.nextInt sc System.out.println(tmpl - l[a-1] - r[S.length()-b]) System.out.println System.out System System.out tmpl - l[a-1] - r[S.length()-b] tmpl - l[a-1] - r[S.length()-b] tmpl l[a-1] l a-1 a 1 r[S.length()-b] r S.length()-b S.length() S.length S b private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    } Scanner String[] s; s int i; i BufferedReader br; br String regex = " "; regex " " public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        } Scanner {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        } s = new String[0] s new String[0] 0 i = 0 i 0 br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        } finalize {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        } try {
                super.finalize();
            } finally {
                destruction();
            } {
                destruction();
            } destruction() destruction {
                super.finalize();
            } super.finalize() super.finalize super private void destruction() throws IOException {
            if (br != null) br.close();
        } destruction {
            if (br != null) br.close();
        } if (br != null) br.close(); br != null br null br.close() br.close br public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        } next {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        } if (i < s.length) return s[i++]; i < s.length i s.length s s.length return s[i++]; s[i++] s i++ i String st = br.readLine(); st br.readLine() br.readLine br while (st == "") st = br.readLine(); st == "" st "" st = br.readLine() st br.readLine() br.readLine br s = st.split(regex, 0) s st.split(regex, 0) st.split st regex 0 i = 0 i 0 return s[i++]; s[i++] s i++ i public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
} public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}