import java.util.Scanner;

public class Main{
    static int[] A,L,R;
    static int N,Q;
    static String str;
    static int ans;
    public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    }

}
/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