import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	} 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[] n = new int[N+1]; n new int[N+1] N+1 N 1 n[0] = 0 n[0] n 0 0 for(int i=0; i<N; i++) {
			if(i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
				n[i+1] = n[i];
				n[i+2] = n[i+1] + 1;
				i++;
			}else {
				n[i+1] = n[i];
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
				n[i+1] = n[i];
				n[i+2] = n[i+1] + 1;
				i++;
			}else {
				n[i+1] = n[i];
			}
		} {
			if(i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
				n[i+1] = n[i];
				n[i+2] = n[i+1] + 1;
				i++;
			}else {
				n[i+1] = n[i];
			}
		} if(i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
				n[i+1] = n[i];
				n[i+2] = n[i+1] + 1;
				i++;
			}else {
				n[i+1] = n[i];
			} i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C' i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C' i+1 < N i+1 i 1 N 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' {
				n[i+1] = n[i];
				n[i+2] = n[i+1] + 1;
				i++;
			} n[i+1] = n[i] n[i+1] n i+1 i 1 n[i] n i n[i+2] = n[i+1] + 1 n[i+2] n i+2 i 2 n[i+1] + 1 n[i+1] n i+1 i 1 1 i++ i {
				n[i+1] = n[i];
			} n[i+1] = n[i] n[i+1] n i+1 i 1 n[i] n i int[] ans = new int[Q]; ans new int[Q] Q for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc ans[i] = n[r]-n[l] ans[i] ans i n[r]-n[l] n[r] n r n[l] n l for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			System.out.println(ans[i]);
		} {
			System.out.println(ans[i]);
		} System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i String[] args args public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	}
} public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

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

		int[] ans = new int[Q];
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans[i] = n[r]-n[l];
		}

		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	}
}
