import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
}




/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