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++) {
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                if (i == 0) {
                    ac.add(1);
                } else {
                    ac.add(ac.get(i - 1) + 1);
                }
            } else {
                if (i == 0) {
                    ac.add(0);
                } else {
                    ac.add(ac.get(i - 1));
                }
            }
        }
        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));
            }
        }
    }

}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz