import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] $) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    }
} import java.util.*; util.* java import java.io.*; io.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] $) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    }
} Main static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] $) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    } main {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String s = sc.next(); s sc.next() sc.next sc int[] AC = new int[n + 1]; AC new int[n + 1] n + 1 n 1 for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        } {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        } if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            } 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' {
                AC[i] = 1;
            } AC[i] = 1 AC[i] AC i 1 for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        } int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
            AC[i] += AC[i - 1];
        } {
            AC[i] += AC[i - 1];
        } AC[i] += AC[i - 1] AC[i] AC i AC[i - 1] AC i - 1 i 1 for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        } {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        } int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int k = 0; k 0 if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++; r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C' r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C' r < n r n s.charAt(r - 1) == 'A' s.charAt(r - 1) s.charAt s r - 1 r 1 'A' s.charAt(r) == 'C' s.charAt(r) s.charAt s r 'C' k++ k out.println(max(0, AC[r] - AC[l - 1] - k)) out.println out max(0, AC[r] - AC[l - 1] - k) max 0 AC[r] - AC[l - 1] - k AC[r] - AC[l - 1] - k AC[r] AC r AC[l - 1] AC l - 1 l 1 k out.close() out.close out String[] $ $ public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] $) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    }
} public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] $) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    }
} Main
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] $) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    }
}
