import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	}

} import java.util.Arrays; Arrays java.util 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(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String s = sc.next(); s sc.next() sc.next sc int ac[] = new int[s.length() + 1]; ac new int[s.length() + 1] s.length() + 1 s.length() s.length s 1 for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		} int i = 1; int i = 1; i 1 i < s.length() i s.length() s.length s i++ i++ i {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		} {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		} ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0 ac[i] ac i s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0 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' 1 0 int psa[] = new int[s.length() + 1]; psa new int[s.length() + 1] s.length() + 1 s.length() s.length s 1 for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		} int i = 1; int i = 1; i 1 i <= s.length() i s.length() s.length s i++ i++ i {
			psa[i] = psa[i - 1] + ac[i];
		} {
			psa[i] = psa[i - 1] + ac[i];
		} psa[i] = psa[i - 1] + ac[i] psa[i] psa i psa[i - 1] + ac[i] psa[i - 1] psa i - 1 i 1 ac[i] ac i for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		} {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		} int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(psa[r - 1] - psa[l - 1]) System.out.println System.out System System.out psa[r - 1] - psa[l - 1] psa[r - 1] psa r - 1 r 1 psa[l - 1] psa l - 1 l 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			ac[i] = s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0;
		}
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i <= s.length(); i++) {
			psa[i] = psa[i - 1] + ac[i];
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	}

}
