import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 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 String S = sc.next(); S sc.next() sc.next sc String[] SSplit = S.split(""); SSplit S.split("") S.split S "" int[][] LR = new int[Q][2]; LR new int[Q][2] Q 2 for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		} {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		} LR[i][0] = sc.nextInt() LR[i][0] LR[i] LR i 0 sc.nextInt() sc.nextInt sc LR[i][1] = sc.nextInt() LR[i][1] LR[i] LR i 1 sc.nextInt() sc.nextInt sc int[] subSum = new int[N]; subSum new int[N] N subSum[0] = 0 subSum[0] subSum 0 0 boolean mode = SSplit[0].equals("A"); mode SSplit[0].equals("A") SSplit[0].equals SSplit[0] SSplit 0 "A" for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		} {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		} if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			} SSplit[i].equals("A") SSplit[i].equals SSplit[i] SSplit i "A" {
				subSum[i] = subSum[i - 1];
				mode = true;
			} subSum[i] = subSum[i - 1] subSum[i] subSum i subSum[i - 1] subSum i - 1 i 1 mode = true mode true if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			} mode && SSplit[i].equals("C") mode SSplit[i].equals("C") SSplit[i].equals SSplit[i] SSplit i "C" {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} subSum[i] = subSum[i - 1] + 1 subSum[i] subSum i subSum[i - 1] + 1 subSum[i - 1] subSum i - 1 i 1 1 mode = false mode false {
				subSum[i] = subSum[i - 1];
				mode = false;
			} subSum[i] = subSum[i - 1] subSum[i] subSum i subSum[i - 1] subSum i - 1 i 1 mode = false mode false for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		} {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		} System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]) System.out.println System.out System System.out subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1] subSum[LR[i][1] - 1] subSum LR[i][1] - 1 LR[i][1] LR[i] LR i 1 1 subSum[LR[i][0] - 1] subSum LR[i][0] - 1 LR[i][0] LR[i] LR i 0 1 String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	}
}