import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

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

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

	}
} Main public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int length = sc.nextInt() length sc.nextInt() sc.nextInt sc q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String s = sc.next(); s sc.next() sc.next sc int[] pSum = new int[length]; pSum new int[length] length for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		} int i = 1; int i = 1; i 1 i < length i length i++ i++ i {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		} {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		} pSum[i] = pSum[i - 1] pSum[i] pSum i pSum[i - 1] pSum i - 1 i 1 if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++; s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' pSum[i]++ pSum[i] pSum i for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		} {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		} int l = sc.nextInt() - 1 l sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 r = sc.nextInt() - 1; r sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]); l == 0 l 0 System.out.println(pSum[r]) System.out.println System.out System System.out pSum[r] pSum r System.out.println(pSum[r] - pSum[l]) System.out.println System.out System System.out pSum[r] - pSum[l] pSum[r] pSum r pSum[l] pSum l String[] args args public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

	}
} public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

	}
} Main
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int length = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		
		int[] pSum = new int[length];
		
		for (int i = 1; i < length; i++) {
			pSum[i] = pSum[i - 1];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') pSum[i]++;
		}
		
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			
			if (l == 0) System.out.println(pSum[r]);
			else System.out.println(pSum[r] - pSum[l]);
		}
		

	}
}