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[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[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[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[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[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[i]);
//		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[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[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int[] a = new int[N + 1]; a new int[N + 1] N + 1 N 1 for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		} {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		} if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			} S.charAt(i) == 'C' && S.charAt(i - 1) == 'A' S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' S.charAt(i - 1) == 'A' S.charAt(i - 1) S.charAt S i - 1 i 1 'A' {
				a[i + 1] += a[i] + 1;
			} a[i + 1] += a[i] + 1 a[i + 1] a i + 1 i 1 a[i] + 1 a[i] a i 1 {
				a[i + 1] = a[i];
			} a[i + 1] = a[i] a[i + 1] a i + 1 i 1 a[i] a i for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			System.out.println(a[r[i]] - a[l[i]]);
		} {
			System.out.println(a[r[i]] - a[l[i]]);
		} System.out.println(a[r[i]] - a[l[i]]) System.out.println System.out System System.out a[r[i]] - a[l[i]] a[r[i]] a r[i] r i a[l[i]] a l[i] l 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[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[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[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[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[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[i]);
//		}
	}
}