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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  }
}

/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