import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	}

	private static void solve(String s, int[] l, int[] r) {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	}

	private static void solvePrint(int[] c, int l, int r) {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	}

	private static void solve(String s, int[] l, int[] r) {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	}

	private static void solvePrint(int[] c, int l, int r) {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	} main {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	} Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in String s = in.next(); s in.next() in.next in int[] l = new int[q]; l new int[q] q int[] r = new int[q]; r new int[q] q for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		} {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		} l[i] = in.nextInt() l[i] l i in.nextInt() in.nextInt in r[i] = in.nextInt() r[i] r i in.nextInt() in.nextInt in solve(s, l, r) solve s l r in.close() in.close in String[] args args private static void solve(String s, int[] l, int[] r) {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	} solve {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	} int[] c = new int[s.length() - 1]; c new int[s.length() - 1] s.length() - 1 s.length() s.length s 1 int ct = 0; ct 0 for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		} int i = 0; int i = 0; i 0 i < s.length() - 1 i s.length() - 1 s.length() s.length s 1 i++ i++ i {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		} {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		} if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++; s.charAt(i) == 'A' && s.charAt(i + 1) == 'C' 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' ct++ ct c[i] = ct c[i] c i ct for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]); int i = 0; int i = 0; i 0 i < l.length i l.length l l.length i++ i++ i solvePrint(c, l[i], r[i]); solvePrint(c, l[i], r[i]) solvePrint c l[i] l i r[i] r i String s s int[] l l int[] r r private static void solvePrint(int[] c, int l, int r) {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	} solvePrint {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	} if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]); l == 1 l 1 System.out.println(c[r - 2]) System.out.println System.out System System.out c[r - 2] c r - 2 r 2 System.out.println(c[r - 2] - c[l - 2]) System.out.println System.out System System.out c[r - 2] - c[l - 2] c[r - 2] c r - 2 r 2 c[l - 2] c l - 2 l 2 int[] c c int l l int r r public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	}

	private static void solve(String s, int[] l, int[] r) {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	}

	private static void solvePrint(int[] c, int l, int r) {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	}

	private static void solve(String s, int[] l, int[] r) {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	}

	private static void solvePrint(int[] c, int l, int r) {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		solve(s, l, r);
		in.close();
	}

	private static void solve(String s, int[] l, int[] r) {
		int[] c = new int[s.length() - 1];
		int ct = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				ct++;
			c[i] = ct;
		}
		for (int i = 0; i < l.length; i++)
			solvePrint(c, l[i], r[i]);
	}

	private static void solvePrint(int[] c, int l, int r) {
		if (l == 1)
			System.out.println(c[r - 2]);
		else
			System.out.println(c[r - 2] - c[l - 2]);
	}
}