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();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	}
} 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();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	}
} 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();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String s = sc.next();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	} 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(); s sc.next() sc.next sc char[] S = s.toCharArray(); S s.toCharArray() s.toCharArray s int[][] q = new int[Q][2]; q new int[Q][2] Q 2 for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		} {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		} q[i][0] = sc.nextInt() q[i][0] q[i] q i 0 sc.nextInt() sc.nextInt sc q[i][1] = sc.nextInt() q[i][1] q[i] q i 1 sc.nextInt() sc.nextInt sc int[] isAcList = new int[S.length]; isAcList new int[S.length] S.length S S.length for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		} int i=0; int i=0; i 0 i<S.length - 1 i S.length - 1 S.length S S.length 1 i++ i++ i {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		} {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		} if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0; S[i] == 'A' && S[i+1] == 'C' S[i] == 'A' S[i] S i 'A' S[i+1] == 'C' S[i+1] S i+1 i 1 'C' isAcList[i] = 1 isAcList[i] isAcList i 1 isAcList[i] = 0 isAcList[i] isAcList i 0 isAcList[S.length - 1] = 0 isAcList[S.length - 1] isAcList S.length - 1 S.length S S.length 1 0 int[] sum = new int[S.length + 1]; sum new int[S.length + 1] S.length + 1 S.length S S.length 1 for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} int i=0; int i=0; i 0 i<S.length i S.length S S.length i++ i++ i {
			sum[i + 1] = sum[i] + isAcList[i];
		} {
			sum[i + 1] = sum[i] + isAcList[i];
		} sum[i + 1] = sum[i] + isAcList[i] sum[i + 1] sum i + 1 i 1 sum[i] + isAcList[i] sum[i] sum i isAcList[i] isAcList i for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		} int i = 0; int i = 0; i 0 i<Q i Q i++ i++ i {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		} {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		} int left = q[i][0] - 1; left q[i][0] - 1 q[i][0] q[i] q i 0 1 int right = q[i][1]; right q[i][1] q[i] q i 1 int ans = sum[right] - sum[left]; ans sum[right] - sum[left] sum[right] sum right sum[left] sum left if (isAcList[right - 1] == 1) ans--; isAcList[right - 1] == 1 isAcList[right - 1] isAcList right - 1 right 1 1 ans-- ans System.out.println(ans) System.out.println System.out System System.out ans 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();
		String s = sc.next();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	}
} 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();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	}
} 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();
	    char[] S = s.toCharArray();
		int[][] q = new int[Q][2];
		for(int i=0; i<Q; i++) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		
		//文字列Sのn番目の文字がAで、その次の文字がCなら１、そうでなければ０を格納
		int[] isAcList = new int[S.length];
		for(int i=0; i<S.length - 1; i++) {
			if( S[i] == 'A' && S[i+1] == 'C') isAcList[i] = 1;
			else isAcList[i] = 0;
		}
		isAcList[S.length - 1] = 0;
		//累積和
		int[] sum = new int[S.length + 1];
		for(int i=0; i<S.length; i++) {
			sum[i + 1] = sum[i] + isAcList[i];
		} 
		
		for(int i = 0; i<Q; i++) {
			int left = q[i][0] - 1;
			int right = q[i][1];
			int ans = sum[right] - sum[left];
			if (isAcList[right - 1] == 1) ans--;
			System.out.println(ans);
		}
	}
}