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[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	}
} 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[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	} 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[] S = sc.next().toCharArray(); S sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] count = new int[n + 1]; count new int[n + 1] n + 1 n 1 for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		} int i = 0; int i = 0; i 0 i < count.length - 1 i count.length - 1 count.length count count.length 1 i++ i++ i {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		} {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		} if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			} i + 1 < n && S[i] == 'A' && S[i + 1] == 'C' i + 1 < n && S[i] == 'A' && S[i + 1] == 'C' i + 1 < n i + 1 i 1 n S[i] == 'A' S[i] S i 'A' S[i + 1] == 'C' S[i + 1] S i + 1 i 1 'C' {
				count[i + 1] = count[i] + 1;
			} count[i + 1] = count[i] + 1 count[i + 1] count i + 1 i 1 count[i] + 1 count[i] count i 1 {
				count[i + 1] = count[i];
			} count[i + 1] = count[i] count[i + 1] count i + 1 i 1 count[i] count i for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		} {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		} int l = sc.nextInt() - 1; l sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int r = sc.nextInt() - 1; r sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 System.out.println(count[r] - count[l]) System.out.println System.out System System.out count[r] - count[l] count[r] count r count[l] count l sc.close() sc.close sc 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[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	}
} 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[] S = sc.next().toCharArray();
		int[] count = new int[n + 1];
		for (int i = 0; i < count.length - 1; i++) {
			if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') {
				count[i + 1] = count[i] + 1;
			} else {
				count[i + 1] = count[i];
			}
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			System.out.println(count[r] - count[l]);
		}
		sc.close();
	}
}