import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	}
} 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(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc int[] cnt = new int[N + 1]; cnt new int[N + 1] N + 1 N 1 String S = sc.next(); S sc.next() sc.next sc for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		} int i = 1; int i = 1; i 1 i < N + 1 i N + 1 N 1 i++ i++ i {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		} {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		} cnt[i] += cnt[i - 1] cnt[i] cnt i cnt[i - 1] cnt i - 1 i 1 if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++; i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A' i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A' i - 2 >= 0 i - 2 i 2 0 S.charAt(i - 1) == 'C' S.charAt(i - 1) S.charAt S i - 1 i 1 'C' S.charAt(i - 2) == 'A' S.charAt(i - 2) S.charAt S i - 2 i 2 'A' cnt[i]++ cnt[i] cnt i for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		} int q = 0; int q = 0; q 0 q < Q q Q q++ q++ q {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		} {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		} int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(cnt[r] - cnt[l]) System.out.println System.out System System.out cnt[r] - cnt[l] cnt[r] cnt r cnt[l] cnt l String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] cnt = new int[N + 1];
		String S = sc.next();
		for(int i = 1; i < N + 1; i++) {
			cnt[i] += cnt[i - 1];
			if(i - 2 >= 0 && S.charAt(i - 1) == 'C' && S.charAt(i - 2) == 'A') cnt[i]++;
		}
		for(int q = 0; q < Q; q++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(cnt[r] - cnt[l]);
		}
	}
}