import java.util.Scanner;

public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	}
} Main static boolean memo[]; memo static int ans ans min; min public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() 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[] cnt = new int[n]; cnt new int[n] n cnt[0] = 0 cnt[0] cnt 0 0 for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		} {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		} if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			} s[i - 1] == 'A' && s[i] == 'C' s[i - 1] == 'A' s[i - 1] s i - 1 i 1 'A' s[i] == 'C' s[i] s i 'C' {
				cnt[i] = cnt[i - 1] + 1;
			} cnt[i] = cnt[i - 1] + 1 cnt[i] cnt i cnt[i - 1] + 1 cnt[i - 1] cnt i - 1 i 1 1 {
				cnt[i] = cnt[i - 1];
			} cnt[i] = cnt[i - 1] cnt[i] cnt i cnt[i - 1] cnt i - 1 i 1 int l l r; r for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		} {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		} l = sc.nextInt() - 1 l sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 r = sc.nextInt() - 1 r sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 sb.append(cnt[r] - cnt[l] + "\n") sb.append sb cnt[r] - cnt[l] + "\n" cnt[r] - cnt[l] cnt[r] cnt r cnt[l] cnt l "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	}
} public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	}
} Main
import java.util.Scanner;

public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] cnt = new int[n];
		cnt[0] = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				cnt[i] = cnt[i - 1] + 1;
			} else {
				cnt[i] = cnt[i - 1];
			}
		}
		int l, r;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			sb.append(cnt[r] - cnt[l] + "\n");
		}
		System.out.print(sb);
	}
}
