import java.util.*;

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[] l = new int[Q];
		int[] r = new int[Q];
		for (int i=0;i<Q;i++) {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}
		int[] SUM = new int[N];
		for (int i=0;i<N-1;i++) {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		}

		for (int i=0;i<Q;i++) {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		}
	}
} import java.util.*; util.* java 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[] l = new int[Q];
		int[] r = new int[Q];
		for (int i=0;i<Q;i++) {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}
		int[] SUM = new int[N];
		for (int i=0;i<N-1;i++) {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		}

		for (int i=0;i<Q;i++) {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		}
	}
} 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[] l = new int[Q];
		int[] r = new int[Q];
		for (int i=0;i<Q;i++) {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}
		int[] SUM = new int[N];
		for (int i=0;i<N-1;i++) {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		}

		for (int i=0;i<Q;i++) {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for (int i=0;i<Q;i++) {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}
		int[] SUM = new int[N];
		for (int i=0;i<N-1;i++) {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		}

		for (int i=0;i<Q;i++) {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		}
	} 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[] 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]=sc.nextInt();
			r[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		} {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		} l[i]=sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i]=sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int[] SUM = new int[N]; SUM new int[N] N for (int i=0;i<N-1;i++) {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		} int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		} {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		} if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			} S.charAt(i)=='A' S.charAt(i) S.charAt S i 'A' {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			} if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				} i!=S.length()-1 && S.charAt(i+1)=='C' i!=S.length()-1 i S.length()-1 S.length() S.length S 1 S.charAt(i+1)=='C' S.charAt(i+1) S.charAt S i+1 i 1 'C' {
					SUM[i+1]=SUM[i]+1;
				} SUM[i+1]=SUM[i]+1 SUM[i+1] SUM i+1 i 1 SUM[i]+1 SUM[i] SUM i 1 {
					SUM[i+1]=SUM[i];
				} SUM[i+1]=SUM[i] SUM[i+1] SUM i+1 i 1 SUM[i] SUM i {
					SUM[i+1]=SUM[i];
			} SUM[i+1]=SUM[i] SUM[i+1] SUM i+1 i 1 SUM[i] SUM i for (int i=0;i<Q;i++) {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		} {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		} System.out.println(SUM[r[i]-1]-SUM[l[i]-1]) System.out.println System.out System System.out SUM[r[i]-1]-SUM[l[i]-1] SUM[r[i]-1] SUM r[i]-1 r[i] r i 1 SUM[l[i]-1] SUM l[i]-1 l[i] l i 1 String[] args args
import java.util.*;

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[] l = new int[Q];
		int[] r = new int[Q];
		for (int i=0;i<Q;i++) {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}
		int[] SUM = new int[N];
		for (int i=0;i<N-1;i++) {
			if (S.charAt(i)=='A') {
				if (i!=S.length()-1 && S.charAt(i+1)=='C') {
					SUM[i+1]=SUM[i]+1;
				}else {
					SUM[i+1]=SUM[i];
				}
			}else {
					SUM[i+1]=SUM[i];
			}
		}

		for (int i=0;i<Q;i++) {
			System.out.println(SUM[r[i]-1]-SUM[l[i]-1]);
		}
	}
}