import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		int n, q;
		char[] input;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		q = scanner.nextInt();
		scanner.nextLine();
		input = scanner.nextLine()
					   .toCharArray();
		int[][] ranges = new int[q][2];
		for (int i = 0; i < q; i++)
		{
			ranges[i][0] = scanner.nextInt();
			ranges[i][1] = scanner.nextInt();
		}
		int[] temp = new int[n];
		int t = 0;
		for (int i = 0; i < n - 1; i++)
		{
			if (input[i] == 'A' && input[i + 1] == 'C')
			{
				t++;
			}
			temp[i + 1] = t;
		}
		for (int[] range : ranges)
		{
			System.out.println(temp[range[1] - 1] - temp[range[0] - 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