import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    }

} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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[] str = s.split(""); str s.split("") s.split s "" List<Integer> l = new ArrayList<>(); l new ArrayList<>() List<Integer> r = new ArrayList<>(); r new ArrayList<>() List<Integer> ac = new ArrayList<>(); ac new ArrayList<>() for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        } {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        } l.add(sc.nextInt()) l.add l sc.nextInt() sc.nextInt sc r.add(sc.nextInt()) r.add r sc.nextInt() sc.nextInt sc for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        } {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        } int prev; prev if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            } i == 0 i 0 {
                prev = 0;
            } prev = 0 prev 0 {
                prev = ac.get(i - 1);
            } prev = ac.get(i - 1) prev ac.get(i - 1) ac.get ac i - 1 i 1 if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            } "A".equals(str[i]) && "C".equals(str[i + 1]) "A".equals(str[i]) "A".equals "A" str[i] str i "C".equals(str[i + 1]) "C".equals "C" str[i + 1] str i + 1 i 1 {
                ac.add(prev + 1);
            } ac.add(prev + 1) ac.add ac prev + 1 prev 1 {
                ac.add(prev);
            } ac.add(prev) ac.add ac prev for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        } {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        } int start = l.get(i); start l.get(i) l.get l i int end = r.get(i); end r.get(i) r.get r i if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            } start == 1 start 1 {
                System.out.println(ac.get(end - 2));
            } System.out.println(ac.get(end - 2)) System.out.println System.out System System.out ac.get(end - 2) ac.get ac end - 2 end 2 {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            } System.out.println(ac.get(end - 2) - ac.get(start - 2)) System.out.println System.out System System.out ac.get(end - 2) - ac.get(start - 2) ac.get(end - 2) ac.get ac end - 2 end 2 ac.get(start - 2) ac.get ac start - 2 start 2 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    }

} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    }

}
