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();
		String S = sc.next();

		int[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

		for(int i=0;i<Q;i++) {
			System.out.println(ans[i]);
		}
	}
} 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();
		String S = sc.next();

		int[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

		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[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

		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[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

		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[] accum = new int[N]; accum new int[N] N boolean flag = false; flag false if(S.charAt(0) == 'A') flag = true; S.charAt(0) == 'A' S.charAt(0) S.charAt S 0 'A' flag = true flag true for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		} int i=1; int i=1; i 1 i<N i N i++ i++ i {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		} {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		} if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			} S.charAt(i) == 'A' S.charAt(i) S.charAt S i 'A' {
				flag = true;
				accum[i] = accum[i-1];
			} flag = true flag true accum[i] = accum[i-1] accum[i] accum i accum[i-1] accum i-1 i 1 if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			} S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			} if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				} flag {
					flag = false;
					accum[i] = accum[i-1] + 1;
				} flag = false flag false accum[i] = accum[i-1] + 1 accum[i] accum i accum[i-1] + 1 accum[i-1] accum i-1 i 1 1 {
					accum[i] = accum[i-1];
				} accum[i] = accum[i-1] accum[i] accum i accum[i-1] accum i-1 i 1 {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			} if(flag) flag = false; flag flag = false flag false accum[i] = accum[i-1] accum[i] accum i accum[i-1] accum i-1 i 1 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] = accum[r-1] - accum[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();
			ans[i] = accum[r-1] - accum[l-1];
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans[i] = accum[r-1] - accum[l-1];
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc ans[i] = accum[r-1] - accum[l-1] ans[i] ans i accum[r-1] - accum[l-1] accum[r-1] accum r-1 r 1 accum[l-1] accum l-1 l 1 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 {

	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[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

		for(int i=0;i<Q;i++) {
			System.out.println(ans[i]);
		}
	}
} public class 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[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

		for(int i=0;i<Q;i++) {
			System.out.println(ans[i]);
		}
	}
} 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();
		String S = sc.next();

		int[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

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

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