import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	}
} import java.io.*; io.* java import java.math.*; math.* java import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	}
} Main public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	} main {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int N = input.nextInt(); N input.nextInt() input.nextInt input int Q = input.nextInt(); Q input.nextInt() input.nextInt input String S = input.next(); S input.next() input.next input int[] AC = new int[N]; AC new int[N] N for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		} {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		} AC[i] = AC[i-1] AC[i] AC i AC[i-1] AC i-1 i 1 if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++; S.charAt(i)=='C'&&S.charAt(i-1)=='A' S.charAt(i)=='C' S.charAt(i) S.charAt S i 'C' S.charAt(i-1)=='A' S.charAt(i-1) S.charAt S i-1 i 1 'A' AC[i]++ AC[i] AC i for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		} {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		} int L = input.nextInt(); L input.nextInt() input.nextInt input int R = input.nextInt(); R input.nextInt() input.nextInt input System.out.println(AC[R-1]-AC[L-1]) System.out.println System.out System System.out AC[R-1]-AC[L-1] AC[R-1] AC R-1 R 1 AC[L-1] AC L-1 L 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	}
} Main
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int Q = input.nextInt();
		String S = input.next();
		int[] AC = new int[N]; //# of AC substrings up to ith index
		for (int i = 1; i < N; i++) {
			AC[i] = AC[i-1];
			if (S.charAt(i)=='C'&&S.charAt(i-1)=='A') AC[i]++;
		}
		//System.out.println(AC[N-1]);
		for (int i = 0; i < Q; i++) {
			int L = input.nextInt();
			int R = input.nextInt();
			System.out.println(AC[R-1]-AC[L-1]);
		}
	}
}