
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc String s = sc.next(); s sc.next() sc.next sc int[] left = new int[m]; left new int[m] m int[] right = new int[m]; right new int[m] m int[] cnt = new int[n+1]; cnt new int[n+1] n+1 n 1 for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		} {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		} left[i] = sc.nextInt() left[i] left i sc.nextInt() sc.nextInt sc right[i] = sc.nextInt() right[i] right i sc.nextInt() sc.nextInt sc for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		} int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		} {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		} if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			} cnt[i-1] != 0 cnt[i-1] cnt i-1 i 1 0 {
				cnt[i] = cnt[i-1];
			} cnt[i] = cnt[i-1] cnt[i] cnt i cnt[i-1] cnt i-1 i 1 if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			} s.substring(i-1, i+1).equals("AC") s.substring(i-1, i+1).equals s.substring(i-1, i+1) s.substring s i-1 i 1 i+1 i 1 "AC" {
				cnt[i] ++ ;
			} cnt[i] ++ cnt[i] cnt i if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		} s.substring(n-2, n).equals("AC") s.substring(n-2, n).equals s.substring(n-2, n) s.substring s n-2 n 2 n "AC" {
			cnt[n-1] = cnt[n-2] + 1;
		} cnt[n-1] = cnt[n-2] + 1 cnt[n-1] cnt n-1 n 1 cnt[n-2] + 1 cnt[n-2] cnt n-2 n 2 1 {
			cnt[n-1] = cnt[n-2];
		} cnt[n-1] = cnt[n-2] cnt[n-1] cnt n-1 n 1 cnt[n-2] cnt n-2 n 2 System.out.println() System.out.println System.out System System.out for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		} {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		} int ans = cnt[right[i]-1] - cnt[left[i]-1]; ans cnt[right[i]-1] - cnt[left[i]-1] cnt[right[i]-1] cnt right[i]-1 right[i] right i 1 cnt[left[i]-1] cnt left[i]-1 left[i] left i 1 System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	}
} Main

import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		int[] left = new int[m];
		int[] right = new int[m];
		int[] cnt = new int[n+1];
		for(int i = 0; i < m; i++) {
			left[i] = sc.nextInt();
			right[i] = sc.nextInt();
		}
		for(int i = 1; i < n-1; i++) {
			if(cnt[i-1] != 0) {
				cnt[i] = cnt[i-1];
			}
			if(s.substring(i-1, i+1).equals("AC")) {
				cnt[i] ++ ;
			}
		}
		if(s.substring(n-2, n).equals("AC")) {
			cnt[n-1] = cnt[n-2] + 1;
		}else {
			cnt[n-1] = cnt[n-2];
		}

		//cnt[n-1] = cnt[n-2];

		System.out.println();
		for(int i = 0; i < m; i++) {
			int ans = cnt[right[i]-1] - cnt[left[i]-1];


			System.out.println(ans);
		}
		sc.close();
	}
}
