import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc int[] arr = new int[N]; arr new int[N] N int[] psa = new int[N]; psa new int[N] N psa[0] = 0 psa[0] psa 0 0 for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		} 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'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		} {
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		} if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			} 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' {
				arr[i] = 1;	
			} arr[i] = 1 arr[i] arr i 1 psa[i]+=arr[i]+psa[i-1] psa[i] psa i arr[i]+psa[i-1] arr[i] arr i psa[i-1] psa i-1 i 1 for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		} {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		} int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(psa[r-1]-psa[l-1]) System.out.println System.out System System.out psa[r-1]-psa[l-1] psa[r-1] psa r-1 r 1 psa[l-1] psa l-1 l 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	}

} Main
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String S = sc.next();
		int[] arr = new int[N];
		int[] psa = new int[N];
		psa[0] = 0;
		for (int i=1; i<N; i++){
			if (S.charAt(i)=='C' && S.charAt(i-1)=='A'){
				arr[i] = 1;	
			}
			psa[i]+=arr[i]+psa[i-1];
		}
		for (int i=0; i<Q; i++){
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r-1]-psa[l-1]);
		}
		
	}

}