import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	}
}
/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