import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	}
	
}

class AC2 {
	int[] acCounts;
	AC2(String s) {
		acCounts = new int[s.length()];
		boolean isBeforeA = false;
		int acCount = 0;
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		}
	}
	int getAC(int l, int r) {
		return acCounts[r - 1] - acCounts[l - 1];
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	}
	
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	} main {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 AC2 ac = new AC2(s); ac new AC2(s) int[] anses = new int[q]; anses new int[q] q for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc anses[i] = ac.getAC(l, r) anses[i] anses i ac.getAC(l, r) ac.getAC ac l r for (int ans : anses) {
			System.out.println(ans);
		} int ans anses {
			System.out.println(ans);
		} {
			System.out.println(ans);
		} System.out.println(ans) System.out.println System.out System System.out ans String[] args args class AC2 {
	int[] acCounts;
	AC2(String s) {
		acCounts = new int[s.length()];
		boolean isBeforeA = false;
		int acCount = 0;
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		}
	}
	int getAC(int l, int r) {
		return acCounts[r - 1] - acCounts[l - 1];
	}
} AC2 int[] acCounts; acCounts AC2(String s) {
		acCounts = new int[s.length()];
		boolean isBeforeA = false;
		int acCount = 0;
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		}
	} AC2 {
		acCounts = new int[s.length()];
		boolean isBeforeA = false;
		int acCount = 0;
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		}
	} acCounts = new int[s.length()] acCounts new int[s.length()] s.length() s.length s boolean isBeforeA = false; isBeforeA false int acCount = 0; acCount 0 for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		} int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		} {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		} char ch = s.charAt(i); ch s.charAt(i) s.charAt s i if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			} isBeforeA {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			} if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				} ch == 'C' ch 'C' {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				} acCount++ acCount acCounts[i] = acCount acCounts[i] acCounts i acCount isBeforeA = false isBeforeA false continue; acCounts[i] = acCount acCounts[i] acCounts i acCount isBeforeA = (ch == 'A') ? true : false isBeforeA (ch == 'A') ? true : false (ch == 'A') ch 'A' true false String s s int getAC(int l, int r) {
		return acCounts[r - 1] - acCounts[l - 1];
	} getAC {
		return acCounts[r - 1] - acCounts[l - 1];
	} return acCounts[r - 1] - acCounts[l - 1]; acCounts[r - 1] - acCounts[l - 1] acCounts[r - 1] acCounts r - 1 r 1 acCounts[l - 1] acCounts l - 1 l 1 int l l int r r public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	}
	
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	}
	
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		AC2 ac = new AC2(s);
		int[] anses = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			anses[i] = ac.getAC(l, r);
		}
		for (int ans : anses) {
			System.out.println(ans);
		}
		
	}
	
}

class AC2 {
	int[] acCounts;
	AC2(String s) {
		acCounts = new int[s.length()];
		boolean isBeforeA = false;
		int acCount = 0;
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (isBeforeA) {
				if (ch == 'C') {
					acCount++;
					acCounts[i] = acCount;
					isBeforeA = false;
					continue;
				}
			}
			acCounts[i] = acCount;
			isBeforeA = (ch == 'A') ? true : false;
		}
	}
	int getAC(int l, int r) {
		return acCounts[r - 1] - acCounts[l - 1];
	}
}
