public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	}
} public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	}
} Main public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	} main {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	} java.util.Scanner sc = new java.util.Scanner(System.in); sc new java.util.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 s[] = new int[N]; s new int[N] N boolean b = false; b false int x = 0; x 0 for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		} {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		} char c = S.charAt(i); c S.charAt(i) S.charAt S i if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			} c == 'A' c 'A' {
				s[i] = x;
				b = true;
			} s[i] = x s[i] s i x b = true b true if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			} b && (c == 'C') b (c == 'C') c 'C' {
				x += 1;
				s[i] = x;
				b = false;
			} x += 1 x 1 s[i] = x s[i] s i x b = false b false {
				s[i] = x;
				b = false;
			} s[i] = x s[i] s i x b = false b false int l = 0; l 0 int r = 0; r 0 for (int i = 0; i < Q; i++) {
			l = sc.nextInt();
			r = sc.nextInt();
			System.out.println(s[r - 1] - s[l - 1]);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			l = sc.nextInt();
			r = sc.nextInt();
			System.out.println(s[r - 1] - s[l - 1]);
		} {
			l = sc.nextInt();
			r = sc.nextInt();
			System.out.println(s[r - 1] - s[l - 1]);
		} l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt() r sc.nextInt() sc.nextInt sc System.out.println(s[r - 1] - s[l - 1]) System.out.println System.out System System.out s[r - 1] - s[l - 1] s[r - 1] s r - 1 r 1 s[l - 1] s l - 1 l 1 String args[] args public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	}
} public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	}
} Main
public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int s[] = new int[N];
		boolean b = false;
		int x = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'A') {
				s[i] = x;
				b = true;
			} else if (b && (c == 'C')) {
				x += 1;
				s[i] = x;
				b = false;
			} else {
				s[i] = x;
				b = false;
			}
		}

		int l = 0;
		int r = 0;

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

	}
}
