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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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[] countAC = new int[n]; countAC new int[n] n for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		} int i = 1; int i = 1; i 1 i < countAC.length i countAC.length countAC countAC.length i++ i++ i {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		} {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		} if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			} String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A") String.valueOf(s.charAt(i)).equals("C") String.valueOf(s.charAt(i)).equals String.valueOf(s.charAt(i)) String.valueOf String s.charAt(i) s.charAt s i "C" String.valueOf(s.charAt(i - 1)).equals("A") String.valueOf(s.charAt(i - 1)).equals String.valueOf(s.charAt(i - 1)) String.valueOf String s.charAt(i - 1) s.charAt s i - 1 i 1 "A" {
				countAC[i] = countAC[i-1] + 1;

			} countAC[i] = countAC[i-1] + 1 countAC[i] countAC i countAC[i-1] + 1 countAC[i-1] countAC i-1 i 1 1 {
				countAC[i] = countAC[i-1];
			} countAC[i] = countAC[i-1] countAC[i] countAC i countAC[i-1] countAC i-1 i 1 for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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 = countAC[r - 1] - countAC[l-1];
			System.out.println(ans);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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 = countAC[r - 1] - countAC[l-1]; ans countAC[r - 1] - countAC[l-1] countAC[r - 1] countAC r - 1 r 1 countAC[l-1] countAC 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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[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[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[l-1];
			System.out.println(ans);
		}
	}
}

