import java.util.*;
import java.io.*;
 
public class Main {
 
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	}
 
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
 
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	}
 
} Main public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	} main {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	} BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int A = Integer.parseInt(st.nextToken()); A Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int Q = Integer.parseInt(st.nextToken()); Q Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st String S = br.readLine(); S br.readLine() br.readLine br int []PrefixSumArr = new int[S.length() + 1]; PrefixSumArr new int[S.length() + 1] S.length() + 1 S.length() S.length S 1 for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		} int i =1; int i =1; i 1 i<S.length() i S.length() S.length S i++ i++ i {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		} {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		} if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			} 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' {
				PrefixSumArr[i]++;
			} PrefixSumArr[i]++ PrefixSumArr[i] PrefixSumArr i for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1]; int i = 1; int i = 1; i 1 i<=S.length() i S.length() S.length S i++ i++ i PrefixSumArr[i] += PrefixSumArr[i-1]; PrefixSumArr[i] += PrefixSumArr[i-1] PrefixSumArr[i] PrefixSumArr i PrefixSumArr[i-1] PrefixSumArr i-1 i 1 for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		} int i =0; int i =0; i 0 i<Q i Q i++ i++ i {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		} {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		} st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) int length = Integer.parseInt(st.nextToken()); length Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int row = Integer.parseInt(st.nextToken()); row Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1]; counter PrefixSumArr[row-1] - PrefixSumArr[length-1] PrefixSumArr[row-1] PrefixSumArr row-1 row 1 PrefixSumArr[length-1] PrefixSumArr length-1 length 1 System.out.println(counter) System.out.println System.out System System.out counter String[] args args public class Main {
 
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	}
 
} public class Main {
 
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	}
 
} Main
import java.util.*;
import java.io.*;
 
public class Main {
 
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	}
 
}