import java.util.ArrayList;
import java.util.Collections;
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();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    }
		
	}
	 import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util 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();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    }
		
	} Main public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    } main {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[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 char[] S = sc.next().toCharArray(); S sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] s = new char[n+1]; s new char[n+1] n+1 n 1 int[] l = new int[q]; l new int[q] q int[] r = new int[q]; r new int[q] q int[] num = new int[n+1]; num new int[n+1] n+1 n 1 int sum = 0; sum 0 for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			} {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			} s[i] = S[i-1] s[i] s i S[i-1] S i-1 i 1 if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				} i>1&&s[i]=='C'&&s[i-1]=='A' i>1&&s[i]=='C'&&s[i-1]=='A' i>1 i 1 s[i]=='C' s[i] s i 'C' s[i-1]=='A' s[i-1] s i-1 i 1 'A' {
					sum++;
				} sum++ sum num[i] = sum num[i] num i sum for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			} int i=0; int i=0; i 0 i<q i q i++ i++ i {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			} {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			} l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			} int i=0; int i=0; i 0 i<q i q i++ i++ i {
				System.out.println(num[r[i]]-num[l[i]]);
			} {
				System.out.println(num[r[i]]-num[l[i]]);
			} System.out.println(num[r[i]]-num[l[i]]) System.out.println System.out System System.out num[r[i]]-num[l[i]] num[r[i]] num r[i] r i num[l[i]] num l[i] l 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();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    }
		
	} public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    }
		
	} Main
import java.util.ArrayList;
import java.util.Collections;
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();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    }
		
	}
	
