import java.util.Scanner;

public class Main {
	public static final String str = "AC";

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	}

//	public static int judgeAndChange(String s) {
//		int ans = 0;
//		while (s.contains(str)) {
//			s = s.replaceFirst(str, "XX");
//			ans++;
//		}
//		return ans;
//	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static final String str = "AC";

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	}

//	public static int judgeAndChange(String s) {
//		int ans = 0;
//		while (s.contains(str)) {
//			s = s.replaceFirst(str, "XX");
//			ans++;
//		}
//		return ans;
//	}
} Main public static final String str = "AC"; str "AC" public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int Q = scanner.nextInt(); Q scanner.nextInt() scanner.nextInt scanner String S = scanner.next(); S scanner.next() scanner.next scanner int[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		} {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		} l[i] = scanner.nextInt() l[i] l i scanner.nextInt() scanner.nextInt scanner r[i] = scanner.nextInt() r[i] r i scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int[] ans = new int[N + 1]; ans new int[N + 1] N + 1 N 1 for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		} {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		} if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[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' {
				ans[i + 1] = ans[i] + 1;
			} ans[i + 1] = ans[i] + 1 ans[i + 1] ans i + 1 i 1 ans[i] + 1 ans[i] ans i 1 {
				ans[i + 1] = ans[i];
			} ans[i + 1] = ans[i] ans[i + 1] ans i + 1 i 1 ans[i] ans i for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		} {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		} System.out.println(ans[r[i]] - ans[l[i]]) System.out.println System.out System System.out ans[r[i]] - ans[l[i]] ans[r[i]] ans r[i] r i ans[l[i]] ans l[i] l i String[] args args public class Main {
	public static final String str = "AC";

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	}

//	public static int judgeAndChange(String s) {
//		int ans = 0;
//		while (s.contains(str)) {
//			s = s.replaceFirst(str, "XX");
//			ans++;
//		}
//		return ans;
//	}
} public class Main {
	public static final String str = "AC";

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	}

//	public static int judgeAndChange(String s) {
//		int ans = 0;
//		while (s.contains(str)) {
//			s = s.replaceFirst(str, "XX");
//			ans++;
//		}
//		return ans;
//	}
} Main
import java.util.Scanner;

public class Main {
	public static final String str = "AC";

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Q = scanner.nextInt();
		String S = scanner.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i = 0; i < Q; i++) {
			l[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
//		for (int i = 0; i < Q; i++) {
//			String s2 = new String(S.substring(l[i] - 1, r[i]));
//			int ans = judgeAndChange(s2);
//			System.out.println(ans);

//		}
		scanner.close();
		int[] ans = new int[N + 1];
		for (int i = 1; i < N; i++) {
//			System.out.println(ans[i]);
			if (S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				ans[i + 1] = ans[i] + 1;
			} else {
				ans[i + 1] = ans[i];
			}
		}
//		for (int i : ans) {
//			System.out.print(i);
//		}
//		System.out.println();
		for (int i = 0; i < Q; i++) {
//			System.out.println("ans[" + r[i] + "]-ans[" + l[i] + "]");
			System.out.println(ans[r[i]] - ans[l[i]]);
		}
	}

//	public static int judgeAndChange(String s) {
//		int ans = 0;
//		while (s.contains(str)) {
//			s = s.replaceFirst(str, "XX");
//			ans++;
//		}
//		return ans;
//	}
}
