import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	}
} Main public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	} main {

		Main main = new Main ();
		main.solve();
	} Main main = new Main (); main new Main () main.solve() main.solve main String[] args args private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	} solve {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	} 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[] list = new int[n]; list new int[n] n int count = 0; count 0 for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		} int index=0; int index=0; index 0 index+1<n index+1 index 1 n index++ index++ index {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		} {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		} if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			} s.charAt(index)=='A'&&s.charAt(index+1)=='C' s.charAt(index)=='A' s.charAt(index) s.charAt s index 'A' s.charAt(index+1)=='C' s.charAt(index+1) s.charAt s index+1 index 1 'C' {
				count++;
			} count++ count list[index+1] = count list[index+1] list index+1 index 1 count for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		} int index=0; int index=0; index 0 index<q index q index++ index++ index {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		} {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		} int first = sc.nextInt(); first sc.nextInt() sc.nextInt sc int last = sc.nextInt(); last sc.nextInt() sc.nextInt sc System.out.println(list[last-1]-list[first-1]) System.out.println System.out System System.out list[last-1]-list[first-1] list[last-1] list last-1 last 1 list[first-1] list first-1 first 1 public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	}
} public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	}
} Main
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] list = new int[n];
		int count = 0;

		for (int index=0; index+1<n; index++) {
			if (s.charAt(index)=='A'&&s.charAt(index+1)=='C') {
				count++;
			}
			list[index+1] = count;
		}

		for (int index=0; index<q; index++) {
			int first = sc.nextInt();
			int last = sc.nextInt();

				System.out.println(list[last-1]-list[first-1]);
		}
	}
}