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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[l-1];
			System.out.println(ans);
		}
	}
} 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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[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[] map = new int[N]; map new int[N] N for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		} int i = 1; int i = 1; i 1 i < S.length() i S.length() S.length S i++ i++ i {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		} {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		} if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[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' map[i]++ map[i] map i for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		} int i = 1; int i = 1; i 1 i < map.length i map.length map map.length i++ i++ i {
			map[i] += map[i-1];
		} {
			map[i] += map[i-1];
		} map[i] += map[i-1] map[i] map i map[i-1] map i-1 i 1 for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[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 = map[r-1] - map[l-1];
			System.out.println(ans);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[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 = map[r-1] - map[l-1]; ans map[r-1] - map[l-1] map[r-1] map r-1 r 1 map[l-1] map 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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[l-1];
			System.out.println(ans);
		}
	}
} Main
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[] map = new int[N];
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') 
				map[i]++;
		}
		
		for (int i = 1; i < map.length; i++) {
			map[i] += map[i-1];
		}
		
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = map[r-1] - map[l-1];
			System.out.println(ans);
		}
	}
}
