import java.util.Arrays;
import java.util.Scanner;
 
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();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		}
	}
 
} import java.util.Arrays; Arrays java.util 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();
		int Q = sc.nextInt();
		String s = sc.next();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			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();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		}
	} main {
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String s = sc.next();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			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 int[] sum = new int[N + 1]; sum new int[N + 1] N + 1 N 1 Arrays.fill(sum, 0) Arrays.fill Arrays sum 0 for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		} {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		} if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i]; i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C' i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C' i + 1 < N i + 1 i 1 N s.charAt(i) == 'A' s.charAt(i) s.charAt s i 'A' s.charAt(i + 1) == 'C' s.charAt(i + 1) s.charAt s i + 1 i 1 'C' sum[i + 1] = sum[i] + 1 sum[i + 1] sum i + 1 i 1 sum[i] + 1 sum[i] sum i 1 sum[i + 1] = sum[i] sum[i + 1] sum i + 1 i 1 sum[i] sum i for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int ans = sum[r - 1] - sum[l - 1]; ans sum[r - 1] - sum[l - 1] sum[r - 1] sum r - 1 r 1 sum[l - 1] sum l - 1 l 1 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();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			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();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		}
	}
 
} Main
import java.util.Arrays;
import java.util.Scanner;
 
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();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		}
	}
 
}