import java.util.*;
public class Main {

	/*
	 * 122C
	 * 
	 * This problem requires prefix sum array
	 * Let's define a boolean array k[i] 
	 * k[i] = true when s[i] == 'A' and s[i+1] == 'C'
	 * Make a prefix sum array of k and then query with it
	 * 
	 * COMMON MISTAKE MAKE SURE YOU DO R-1 BECAUSE S[R+1] GOES OVER THE RANGE
	 * COMMON MISTAKE THIS IS ONE-INDEXED STRING
	 * 
	 * Time Complexity O(N), Memory Complexity O(N)
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String s = sc.next();
		int pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		}
	}
} import java.util.*; util.* java public class Main {

	/*
	 * 122C
	 * 
	 * This problem requires prefix sum array
	 * Let's define a boolean array k[i] 
	 * k[i] = true when s[i] == 'A' and s[i+1] == 'C'
	 * Make a prefix sum array of k and then query with it
	 * 
	 * COMMON MISTAKE MAKE SURE YOU DO R-1 BECAUSE S[R+1] GOES OVER THE RANGE
	 * COMMON MISTAKE THIS IS ONE-INDEXED STRING
	 * 
	 * Time Complexity O(N), Memory Complexity O(N)
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String s = sc.next();
		int pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[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 pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String s = sc.next();
		int pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[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 pre[] = new int[N+1]; pre new int[N+1] N+1 N 1 for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		} int i = 1; int i = 1; i 1 i<N i N i++ i++ i {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		} {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		} if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			} s.charAt(i-1) == 'A' && s.charAt(i) =='C' s.charAt(i-1) == 'A' s.charAt(i-1) s.charAt s i-1 i 1 'A' s.charAt(i) =='C' s.charAt(i) s.charAt s i 'C' {
				pre[i] = 1; //initially the prefix sum array is the k array
			} pre[i] = 1 pre[i] pre i 1 for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		} int i = 1; int i = 1; i 1 i<N i N i++ i++ i {
			pre[i] += pre[i-1];
		} {
			pre[i] += pre[i-1];
		} pre[i] += pre[i-1] pre[i] pre i pre[i-1] pre i-1 i 1 while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		} Q-- > 0 Q-- Q 0 {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		} int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc r-- r System.out.println(pre[r] - pre[l-1]) System.out.println System.out System System.out pre[r] - pre[l-1] pre[r] pre r pre[l-1] pre l-1 l 1 String[] args args public class Main {

	/*
	 * 122C
	 * 
	 * This problem requires prefix sum array
	 * Let's define a boolean array k[i] 
	 * k[i] = true when s[i] == 'A' and s[i+1] == 'C'
	 * Make a prefix sum array of k and then query with it
	 * 
	 * COMMON MISTAKE MAKE SURE YOU DO R-1 BECAUSE S[R+1] GOES OVER THE RANGE
	 * COMMON MISTAKE THIS IS ONE-INDEXED STRING
	 * 
	 * Time Complexity O(N), Memory Complexity O(N)
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String s = sc.next();
		int pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		}
	}
} public class Main {

	/*
	 * 122C
	 * 
	 * This problem requires prefix sum array
	 * Let's define a boolean array k[i] 
	 * k[i] = true when s[i] == 'A' and s[i+1] == 'C'
	 * Make a prefix sum array of k and then query with it
	 * 
	 * COMMON MISTAKE MAKE SURE YOU DO R-1 BECAUSE S[R+1] GOES OVER THE RANGE
	 * COMMON MISTAKE THIS IS ONE-INDEXED STRING
	 * 
	 * Time Complexity O(N), Memory Complexity O(N)
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String s = sc.next();
		int pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		}
	}
} Main
import java.util.*;
public class Main {

	/*
	 * 122C
	 * 
	 * This problem requires prefix sum array
	 * Let's define a boolean array k[i] 
	 * k[i] = true when s[i] == 'A' and s[i+1] == 'C'
	 * Make a prefix sum array of k and then query with it
	 * 
	 * COMMON MISTAKE MAKE SURE YOU DO R-1 BECAUSE S[R+1] GOES OVER THE RANGE
	 * COMMON MISTAKE THIS IS ONE-INDEXED STRING
	 * 
	 * Time Complexity O(N), Memory Complexity O(N)
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		String s = sc.next();
		int pre[] = new int[N+1];
		for(int i = 1; i<N; i++) {
			if(s.charAt(i-1) == 'A' && s.charAt(i) =='C') {
				pre[i] = 1; //initially the prefix sum array is the k array
			}
		}
		//Building the psa
		for(int i = 1; i<N; i++) {
			pre[i] += pre[i-1];
		}
		//Querying
		while(Q-- > 0) {
			int l = sc.nextInt(), r = sc.nextInt();
			r--;
			System.out.println(pre[r] - pre[l-1]);
		}
	}
}
