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();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	}

} 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();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	}

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	} 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 char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] counts = new int[N]; counts new int[N] N int[] results = new int[Q]; results new int[Q] Q boolean aFlag = false; aFlag false int count = 0; count 0 for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		} int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		} {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		} if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			} c[j] == 'A' c[j] c j 'A' {
				aFlag = true;
			} aFlag = true aFlag true if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			} aFlag {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			} if (c[j] == 'C') {
					count++;
				} c[j] == 'C' c[j] c j 'C' {
					count++;
				} count++ count aFlag = false aFlag false counts[j] = count counts[j] counts j count for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int forL = counts[l-1]; forL counts[l-1] counts l-1 l 1 int forR = counts[r-1]; forR counts[r-1] counts r-1 r 1 results[i] = forR - forL results[i] results i forR - forL forR forL for (int k : results) {
			System.out.println(k);
		} int k results {
			System.out.println(k);
		} {
			System.out.println(k);
		} System.out.println(k) System.out.println System.out System System.out k 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();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	}

} 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();

		char[] c = sc.next().toCharArray();
		int[] counts = new int[N];
		int[] results = new int[Q];
		boolean aFlag = false;
		int count = 0;
		for (int j = 0; j < N; j++) {
			if (c[j] == 'A') {
				aFlag = true;
			} else if (aFlag) {
				if (c[j] == 'C') {
					count++;
				}
				aFlag = false;
			}
			counts[j] = count;
		}
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int forL = counts[l-1];
			int forR = counts[r-1];

			results[i] = forR - forL;

		}

		for (int k : results) {
			System.out.println(k);
		}
	}

}