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[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	}

	private static int[] getAcCount(String input,int n) {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	}

} 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[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	}

	private static int[] getAcCount(String input,int n) {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	}

} 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[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	} main {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	} 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[] acArray = getAcCount(s,n); acArray getAcCount(s,n) getAcCount s n for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		} {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		} int start = sc.nextInt(); start sc.nextInt() sc.nextInt sc int end = sc.nextInt(); end sc.nextInt() sc.nextInt sc System.out.println(acArray[end]-acArray[start]) System.out.println System.out System System.out acArray[end]-acArray[start] acArray[end] acArray end acArray[start] acArray start String[] args args private static int[] getAcCount(String input,int n) {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	} getAcCount {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	} int[] acArray = new int[n +1]; acArray new int[n +1] n +1 n 1 String[] inputArray = input.split(""); inputArray input.split("") input.split input "" int acCount = 0; acCount 0 for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		} int i=0; int i=0; i 0 i < inputArray.length i inputArray.length inputArray inputArray.length i++ i++ i {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		} {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		} if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			} !inputArray[i].equals("A") inputArray[i].equals("A") inputArray[i].equals inputArray[i] inputArray i "A" {
				acArray[i+1] = acCount;
				continue;
			} acArray[i+1] = acCount acArray[i+1] acArray i+1 i 1 acCount continue; {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			} if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				} i == inputArray.length-1 i inputArray.length-1 inputArray.length inputArray inputArray.length 1 {
					acArray[i+1] = acCount;
					break;
				} acArray[i+1] = acCount acArray[i+1] acArray i+1 i 1 acCount break; if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				} inputArray[i+1].equals("C") inputArray[i+1].equals inputArray[i+1] inputArray i+1 i 1 "C" {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				} acArray[i+1] = acCount acArray[i+1] acArray i+1 i 1 acCount acCount++ acCount acArray[i+2] = acCount acArray[i+2] acArray i+2 i 2 acCount {
					acArray[i+1] = acCount;
				} acArray[i+1] = acCount acArray[i+1] acArray i+1 i 1 acCount return acArray; acArray String input input int n n 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[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	}

	private static int[] getAcCount(String input,int n) {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	}

} 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[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	}

	private static int[] getAcCount(String input,int n) {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	}

} 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[] acArray = getAcCount(s,n);
		for(int i = 0;i < q; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			System.out.println(acArray[end]-acArray[start]);
		}
	}

	private static int[] getAcCount(String input,int n) {
		int[] acArray = new int[n +1];
		String[] inputArray = input.split("");
		int acCount = 0;
		for(int i=0;i < inputArray.length;i++) {
			if(!inputArray[i].equals("A")) {
				acArray[i+1] = acCount;
				continue;
			}else {
				if(i == inputArray.length-1) {
					acArray[i+1] = acCount;
					break;
				}
				if(inputArray[i+1].equals("C")) {
					acArray[i+1] = acCount;
					acCount++;
					acArray[i+2] = acCount;
				}else {
					acArray[i+1] = acCount;
				}
			}
		}

		return acArray;
	}

}