//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    }
} Main public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    } main {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    } FastScanner sc = new FastScanner(); sc new FastScanner() PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc m = sc.nextInt(); m sc.nextInt() sc.nextInt sc String str = sc.nextLine(); str sc.nextLine() sc.nextLine sc int[] cnt = new int[n]; cnt new int[n] n for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        } {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        } cnt[i] = cnt[i-1] cnt[i] cnt i cnt[i-1] cnt i-1 i 1 if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            } str.charAt(i) == 'C' && str.charAt(i-1) == 'A' str.charAt(i) == 'C' str.charAt(i) str.charAt str i 'C' str.charAt(i-1) == 'A' str.charAt(i-1) str.charAt str i-1 i 1 'A' {
                cnt[i]++;
            } cnt[i]++ cnt[i] cnt i for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        } {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        } int l = sc.nextInt() - 1 l sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 r = sc.nextInt() - 1; r sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 pw.println(cnt[r] - cnt[l]) pw.println pw cnt[r] - cnt[l] cnt[r] cnt r cnt[l] cnt l pw.close() pw.close pw String[] args args static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    } FastScanner BufferedReader br; br StringTokenizer st; st public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        } FastScanner {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        } try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();} catch (Exception e){e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        } next {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        } if (st.hasMoreTokens()) return st.nextToken(); st.hasMoreTokens() st.hasMoreTokens st return st.nextToken(); st.nextToken() st.nextToken st try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {st = new StringTokenizer(br.readLine());} st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {return Integer.parseInt(next());} nextInt {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {return Long.parseLong(next());} nextLong {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {return Double.parseDouble(next());} nextDouble {return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        } nextLine {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        } String line = ""; line "" if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();} st.hasMoreTokens() st.hasMoreTokens st line = st.nextToken() line st.nextToken() st.nextToken st try {return br.readLine();}catch(IOException e){e.printStackTrace();} catch(IOException e){e.printStackTrace();} IOException e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {return br.readLine();} return br.readLine(); br.readLine() br.readLine br while(st.hasMoreTokens()) line += " "+st.nextToken(); st.hasMoreTokens() st.hasMoreTokens st line += " "+st.nextToken() line " "+st.nextToken() " " st.nextToken() st.nextToken st return line; line public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    }
} public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    }
} Main
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    }
}
