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