import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	}
} Main public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	} main {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	} Scanner stdIn=new Scanner(System.in); stdIn new Scanner(System.in) int N=stdIn.nextInt(); N stdIn.nextInt() stdIn.nextInt stdIn int Q=stdIn.nextInt(); Q stdIn.nextInt() stdIn.nextInt stdIn int ans[]=new int[N]; ans new int[N] N int kota[]=new int[Q]; kota new int[Q] Q String S=stdIn.next(); S stdIn.next() stdIn.next stdIn int z=1 z 1 y=0 y 0 l=0 l 0 r=0 r 0 num=0; num 0 while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		} z<N z N {
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		} if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			} S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A") S.substring(z,z+1).equals("C") S.substring(z,z+1).equals S.substring(z,z+1) S.substring S z z+1 z 1 "C" S.substring(z-1,z).equals("A") S.substring(z-1,z).equals S.substring(z-1,z) S.substring S z-1 z 1 z "A" {
				y++;
			} y++ y ans[z]=y ans[z] ans z y z++ z z=0 z 0 y=0 y 0 while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		} z<Q z Q {
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		} l=stdIn.nextInt() l stdIn.nextInt() stdIn.nextInt stdIn r=stdIn.nextInt() r stdIn.nextInt() stdIn.nextInt stdIn kota[z]=ans[r-1]-ans[l-1] kota[z] kota z ans[r-1]-ans[l-1] ans[r-1] ans r-1 r 1 ans[l-1] ans l-1 l 1 z++ z z=0 z 0 while(z<Q){
			System.out.println(kota[z]);
			z++;
		} z<Q z Q {
			System.out.println(kota[z]);
			z++;
		} System.out.println(kota[z]) System.out.println System.out System System.out kota[z] kota z z++ z String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	}
}