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

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		sc.close();

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

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		sc.close();

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

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		sc.close();

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		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 String s = sc.next(); s sc.next() sc.next sc int[] cnt = new int[n + 1]; cnt new int[n + 1] n + 1 n 1 for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		} {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		} if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			} s.charAt(i) == 'A' && s.charAt(i + 1) == 'C' s.charAt(i) == 'A' s.charAt(i) s.charAt s i 'A' s.charAt(i + 1) == 'C' s.charAt(i + 1) s.charAt s i + 1 i 1 'C' {
				cnt[i + 1] = cnt[i] + 1;
			} cnt[i + 1] = cnt[i] + 1 cnt[i + 1] cnt i + 1 i 1 cnt[i] + 1 cnt[i] cnt i 1 {
				cnt[i + 1] = cnt[i];
			} cnt[i + 1] = cnt[i] cnt[i + 1] cnt i + 1 i 1 cnt[i] cnt i for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(cnt[r - 1] - cnt[l - 1]) System.out.println System.out System System.out cnt[r - 1] - cnt[l - 1] cnt[r - 1] cnt r - 1 r 1 cnt[l - 1] cnt l - 1 l 1 sc.close() sc.close sc 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();

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		sc.close();

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

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		sc.close();

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

		int[] cnt = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				cnt[i + 1] = cnt[i] + 1;
			} else {
				cnt[i + 1] = cnt[i];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			System.out.println(cnt[r - 1] - cnt[l - 1]);
		}
		sc.close();

	}
}
