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