import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	}
}


 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	}
} Main public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	} main {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	} Scanner reader = new Scanner(System.in); reader new Scanner(System.in) int N = reader.nextInt(); N reader.nextInt() reader.nextInt reader int Q = reader.nextInt(); Q reader.nextInt() reader.nextInt reader String S = reader.next(); S reader.next() reader.next reader int[] arr = new int[N]; arr new int[N] N int[] beginIndex =  new int[Q]; beginIndex new int[Q] Q int[] endIndex =  new int[Q]; endIndex new int[Q] Q for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		} {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		} beginIndex[i] = reader.nextInt() - 1 beginIndex[i] beginIndex i reader.nextInt() - 1 reader.nextInt() reader.nextInt reader 1 endIndex[i] = reader.nextInt() - 1 endIndex[i] endIndex i reader.nextInt() - 1 reader.nextInt() reader.nextInt reader 1 for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		} {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		} arr[i+1] = arr[i] arr[i+1] arr i+1 i 1 arr[i] arr i String tmp = S.substring(i, i+2); tmp S.substring(i, i+2) S.substring S i i+2 i 2 if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			} tmp.equals("AC") tmp.equals tmp "AC" {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			} arr[i+1]++ arr[i+1] arr i+1 i 1 if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				} i < N -2 i N -2 N 2 {
					arr[i+2]  = arr[i+1];
					i++;
				} arr[i+2]  = arr[i+1] arr[i+2] arr i+2 i 2 arr[i+1] arr i+1 i 1 i++ i for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		} {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		} int a = arr[endIndex[i]] - arr[beginIndex[i]]; a arr[endIndex[i]] - arr[beginIndex[i]] arr[endIndex[i]] arr endIndex[i] endIndex i arr[beginIndex[i]] arr beginIndex[i] beginIndex i int ans = Math.max(a, 0); ans Math.max(a, 0) Math.max Math a 0 System.out.println(ans) System.out.println System.out System System.out ans reader.close() reader.close reader String[] args args public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int Q = reader.nextInt();
		String S = reader.next();
		int[] arr = new int[N];
		int[] beginIndex =  new int[Q];
		int[] endIndex =  new int[Q];
		for (int i = 0; i < Q; i++) {
			beginIndex[i] = reader.nextInt() - 1;
			endIndex[i] = reader.nextInt() - 1;
		}

		for (int i = 0; i < N - 1; i++) {
			arr[i+1] = arr[i];
			String tmp = S.substring(i, i+2);
			if (tmp.equals("AC")) {
				arr[i+1]++;
				if (i < N -2) {
					arr[i+2]  = arr[i+1];
					i++;
				}
			}
		}
		for (int i = 0; i < Q; i++) {
			int a = arr[endIndex[i]] - arr[beginIndex[i]];
			int ans = Math.max(a, 0);
			System.out.println(ans);
		}
		reader.close();
	}
}



