import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String ss = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i = 0;i < Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		int[] ruisekiwa = new int[N+1];
		ruisekiwa[0] = 0;
		for(int i = 0;i < N-1;i++){
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		}
		
		
		int[] ans = new int[Q];

		for(int i = 0;i < Q;i++){
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		}

		for(int i = 0;i < Q;i++){
			System.out.println(ans[i]);
		}


	}


}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}

 import java.util.Scanner; Scanner java.util class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String ss = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i = 0;i < Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		int[] ruisekiwa = new int[N+1];
		ruisekiwa[0] = 0;
		for(int i = 0;i < N-1;i++){
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		}
		
		
		int[] ans = new int[Q];

		for(int i = 0;i < Q;i++){
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		}

		for(int i = 0;i < Q;i++){
			System.out.println(ans[i]);
		}


	}


} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String ss = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i = 0;i < Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		int[] ruisekiwa = new int[N+1];
		ruisekiwa[0] = 0;
		for(int i = 0;i < N-1;i++){
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		}
		
		
		int[] ans = new int[Q];

		for(int i = 0;i < Q;i++){
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		}

		for(int i = 0;i < Q;i++){
			System.out.println(ans[i]);
		}


	} main {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String ss = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i = 0;i < Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		int[] ruisekiwa = new int[N+1];
		ruisekiwa[0] = 0;
		for(int i = 0;i < N-1;i++){
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		}
		
		
		int[] ans = new int[Q];

		for(int i = 0;i < Q;i++){
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		}

		for(int i = 0;i < Q;i++){
			System.out.println(ans[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 ss = sc.next(); ss sc.next() sc.next sc int[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q 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 int[] ruisekiwa = new int[N+1]; ruisekiwa new int[N+1] N+1 N 1 ruisekiwa[0] = 0 ruisekiwa[0] ruisekiwa 0 0 for(int i = 0;i < N-1;i++){
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		} int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		} {
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		} if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			} ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C' ss.charAt(i) == 'A' ss.charAt(i) ss.charAt ss i 'A' ss.charAt(i+1) == 'C' ss.charAt(i+1) ss.charAt ss i+1 i 1 'C' {
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			} ruisekiwa[i+1] = ruisekiwa[i] + 1 ruisekiwa[i+1] ruisekiwa i+1 i 1 ruisekiwa[i] + 1 ruisekiwa[i] ruisekiwa i 1 {
				ruisekiwa[i+1] = ruisekiwa[i];
			} ruisekiwa[i+1] = ruisekiwa[i] ruisekiwa[i+1] ruisekiwa i+1 i 1 ruisekiwa[i] ruisekiwa i int[] ans = new int[Q]; ans new int[Q] Q for(int i = 0;i < Q;i++){
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		} {
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		} int count = 0; count 0 ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1] ans[i] ans i ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1] ruisekiwa[r[i]-1] ruisekiwa r[i]-1 r[i] r i 1 ruisekiwa[l[i]-1] ruisekiwa l[i]-1 l[i] l i 1 for(int i = 0;i < Q;i++){
			System.out.println(ans[i]);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			System.out.println(ans[i]);
		} {
			System.out.println(ans[i]);
		} System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i String[] args args class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
} Pair int from; from int end; end @Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	} compareTo {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	} Pair otherpair = (Pair)other; otherpair (Pair)other return from - otherpair.from; from - otherpair.from from otherpair.from otherpair otherpair.from Object other other Comparable
import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String ss = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i = 0;i < Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		int[] ruisekiwa = new int[N+1];
		ruisekiwa[0] = 0;
		for(int i = 0;i < N-1;i++){
			if(ss.charAt(i) == 'A' && ss.charAt(i+1) == 'C'){
				ruisekiwa[i+1] = ruisekiwa[i] + 1;
			}else{
				ruisekiwa[i+1] = ruisekiwa[i];
			}
		}
		
		
		int[] ans = new int[Q];

		for(int i = 0;i < Q;i++){
			int count = 0;
			ans[i] = ruisekiwa[r[i]-1] - ruisekiwa[l[i]-1];
		}

		for(int i = 0;i < Q;i++){
			System.out.println(ans[i]);
		}


	}


}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}


