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[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[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[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[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[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[i]]);
		}



	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();

		String S = sc.next();

		int[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[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[] kukan = new int[2*Q]; kukan new int[2*Q] 2*Q 2 Q for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		} int i = 0 ; int i = 0 ; i 0 i < 2*Q i 2*Q 2 Q i++ i++ i {
			kukan[i] = sc.nextInt()-1;
		} {
			kukan[i] = sc.nextInt()-1;
		} kukan[i] = sc.nextInt()-1 kukan[i] kukan i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 sc.close() sc.close sc int[] AC = new int[N]; AC new int[N] N int count = 0; count 0 for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		} int i = 0 ; int i = 0 ; i 0 i < N-1 i N-1 N 1 i++ i++ i {
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		} {
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		} if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			} S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C") S.substring(i, i+1).equals("A") S.substring(i, i+1).equals S.substring(i, i+1) S.substring S i i+1 i 1 "A" S.substring(i+1, i+2).equals("C") S.substring(i+1, i+2).equals S.substring(i+1, i+2) S.substring S i+1 i 1 i+2 i 2 "C" {
				count++;
			} count++ count AC[i+1] = count AC[i+1] AC i+1 i 1 count for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[i]]);
		} int i = 0 ; int i = 0 ; i 0 i < 2*Q i 2*Q 2 Q i+=2 i+=2 i 2 {
				System.out.println(AC[kukan[i+1]] - AC[kukan[i]]);
		} {
				System.out.println(AC[kukan[i+1]] - AC[kukan[i]]);
		} System.out.println(AC[kukan[i+1]] - AC[kukan[i]]) System.out.println System.out System System.out AC[kukan[i+1]] - AC[kukan[i]] AC[kukan[i+1]] AC kukan[i+1] kukan i+1 i 1 AC[kukan[i]] AC kukan[i] kukan 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[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[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[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[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[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[i]]);
		}



	}
}