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