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[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	}
} 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[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	}
} 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[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	} 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[] acarr = new int[100000]; acarr new int[100000] 100000 int count = 0; count 0 for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		} int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		} {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		} if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			} s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0 s.charAt(i - 1) == 'A' s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0 s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' i != 0 i 0 s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' i != 0 i 0 {
				count++;
				acarr[i] = count;
			} count++ count acarr[i] = count acarr[i] acarr i count {
				acarr[i]=count;
			} acarr[i]=count acarr[i] acarr i count for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		} int i=0; int i=0; i 0 i<q i q i++ i++ i {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		} {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		} int l1=sc.nextInt()-1; l1 sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int l2=sc.nextInt()-1; l2 sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 System.out.println(acarr[l2]-acarr[l1]) System.out.println System.out System System.out acarr[l2]-acarr[l1] acarr[l2] acarr l2 acarr[l1] acarr l1 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[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	}
} 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[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	}
} 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[] acarr = new int[100000];
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'C' && i != 0 && s.charAt(i - 1) == 'A' && i != 0) {
				count++;
				acarr[i] = count;
			}else {
				acarr[i]=count;
			}
		}

		for(int i=0;i<q;i++) {
			int l1=sc.nextInt()-1;
			int l2=sc.nextInt()-1;
			System.out.println(acarr[l2]-acarr[l1]);
		}
	}
}
