import 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();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]);
	}
	
	
	static boolean isAC(String x,String y){
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]);
	}
	
	
	static boolean isAC(String x,String y){
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]);
	} main {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[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 String[] s = sc.next().split(""); s sc.next().split("") sc.next().split sc.next() sc.next sc "" int[] t = new int[n]; t new int[n] n t[0]=0 t[0] t 0 0 for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		} int i=1; int i=1; i 1 i<t.length i t.length t t.length i++ i++ i {
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		} {
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		} t[i]=t[i-1] t[i] t i t[i-1] t i-1 i 1 if(isAC(s[i-1],s[i]))t[i]++; isAC(s[i-1],s[i]) isAC s[i-1] s i-1 i 1 s[i] s i t[i]++ t[i] t i int[] pnt=new int[q]; pnt new int[q] q for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		} int i=0; int i=0; i 0 i<q i q i++ i++ i {
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		} {
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		} int l= sc.nextInt()-1; l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int r= sc.nextInt()-1; r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 pnt[i]=t[r]-t[l] pnt[i] pnt i t[r]-t[l] t[r] t r t[l] t l for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]); int i=0; int i=0; i 0 i<pnt.length i pnt.length pnt pnt.length i++ i++ i System.out.println(pnt[i]); System.out.println(pnt[i]) System.out.println System.out System System.out pnt[i] pnt i String[] args args static boolean isAC(String x,String y){
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	} isAC {
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	} if(x.equals("A")&&y.equals("C"))return true;
		else return false; x.equals("A")&&y.equals("C") x.equals("A") x.equals x "A" y.equals("C") y.equals y "C" return true; true return false; false String x x String y y public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]);
	}
	
	
	static boolean isAC(String x,String y){
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]);
	}
	
	
	static boolean isAC(String x,String y){
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	}
} Main
import 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();
		String[] s = sc.next().split("");
		int[] t = new int[n];
		t[0]=0;
		for(int i=1;i<t.length;i++){
			t[i]=t[i-1];
			if(isAC(s[i-1],s[i]))t[i]++;
		}
		int[] pnt=new int[q];
		for(int i=0;i<q;i++){
			int l= sc.nextInt()-1;
			int r= sc.nextInt()-1;
			pnt[i]=t[r]-t[l];
		}
		for(int i=0;i<pnt.length;i++)System.out.println(pnt[i]);
	}
	
	
	static boolean isAC(String x,String y){
		if(x.equals("A")&&y.equals("C"))return true;
		else return false;
	}
}