import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	}

} Main public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	} main {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	} final Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) final int counter = scanner.nextInt(); counter scanner.nextInt() scanner.nextInt scanner final int loop = scanner.nextInt(); loop scanner.nextInt() scanner.nextInt scanner scanner.nextLine() scanner.nextLine scanner final String line = scanner.nextLine(); line scanner.nextLine() scanner.nextLine scanner final int[][] index = new int[loop][2]; index new int[loop][2] loop 2 final int[] array = new int[counter]; array new int[counter] counter for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i<loop i loop i++ i++ i {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		} {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		} index[i][0] = scanner.nextInt() index[i][0] index[i] index i 0 scanner.nextInt() scanner.nextInt scanner index[i][1] = scanner.nextInt() index[i][1] index[i] index i 1 scanner.nextInt() scanner.nextInt scanner for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		} int i = 1; int i = 1; i 1 i < counter i counter i++ i++ i {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		} {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		} array[i] = array[i - 1] array[i] array i array[i - 1] array i - 1 i 1 if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			} line.charAt(i) == 'C' && line.charAt(i - 1) == 'A' line.charAt(i) == 'C' line.charAt(i) line.charAt line i 'C' line.charAt(i - 1) == 'A' line.charAt(i - 1) line.charAt line i - 1 i 1 'A' {
				array[i]++;
			} array[i]++ array[i] array i for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		} int i = 0; int i = 0; i 0 i < loop i loop i++ i++ i {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		} {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		} final int begin = index[i][0]; begin index[i][0] index[i] index i 0 final int end = index[i][1]; end index[i][1] index[i] index i 1 System.out.println(array[end - 1] - array[begin - 1]) System.out.println System.out System System.out array[end - 1] - array[begin - 1] array[end - 1] array end - 1 end 1 array[begin - 1] array begin - 1 begin 1 scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	}

} public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	}

}