import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc String s = sc.nextLine(); s sc.nextLine() sc.nextLine sc int[] sum = new int[s.length()]; sum new int[s.length()] s.length() s.length s for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		} int i = 1; int i = 1; i 1 i < s.length() i s.length() s.length s i++ i++ i {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		} {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		} sum[i] = sum[i - 1] sum[i] sum i sum[i - 1] sum i - 1 i 1 if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++; s.charAt(i) == 'C' && s.charAt(i - 1) == 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' sum[i]++ sum[i] sum i while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		} q-- > 0 q-- q 0 {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(sum[r - 1] - sum[l - 1]) System.out.println System.out System System.out sum[r - 1] - sum[l - 1] sum[r - 1] sum r - 1 r 1 sum[l - 1] sum l - 1 l 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int[] sum = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			sum[i] = sum[i - 1];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') sum[i]++;
		}

		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(sum[r - 1] - sum[l - 1]);
		}
	}
}
