import java.util.*;
import java.lang.*;

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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	}
} import java.util.*; util.* java import java.lang.*; lang.* java 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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	}
} 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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	} 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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	} 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() - 1;
			r[i] = sc.nextInt() - 1;
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			l[i] = sc.nextInt() - 1;
			r[i] = sc.nextInt() - 1;
		} {
			l[i] = sc.nextInt() - 1;
			r[i] = sc.nextInt() - 1;
		} l[i] = sc.nextInt() - 1 l[i] l i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 r[i] = sc.nextInt() - 1 r[i] r i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 Set<Integer> set = new TreeSet<>(); set new TreeSet<>() int[] sum = new int[n]; sum new int[n] n int count = 0; count 0 for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		} {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		} if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			} s.substring(i, i + 2).equals("AC") s.substring(i, i + 2).equals s.substring(i, i + 2) s.substring s i i + 2 i 2 "AC" {
				count++;
				set.add(i);
			} count++ count set.add(i) set.add set i sum[i] = count sum[i] sum i count sum[n - 1] = count sum[n - 1] sum n - 1 n 1 count for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		} {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		} if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			} set.contains(r[i]) set.contains set r[i] r i {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				} set.contains(l[i]) set.contains set l[i] l 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 System.out System System.out sum[r[i]] - 1 - sum[l[i]] + 1 sum[r[i]] - 1 - sum[l[i]] sum[r[i]] - 1 - sum[l[i]] sum[r[i]] sum r[i] r i 1 sum[l[i]] sum l[i] l i 1 {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				} System.out.println(sum[r[i]] - 1 - sum[l[i]]) System.out.println System.out System System.out sum[r[i]] - 1 - sum[l[i]] sum[r[i]] - 1 - sum[l[i]] sum[r[i]] sum r[i] r i 1 sum[l[i]] sum l[i] l i {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			} if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				} set.contains(l[i]) set.contains set l[i] l i {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} System.out.println(sum[r[i]] - sum[l[i]] + 1) System.out.println System.out System System.out sum[r[i]] - sum[l[i]] + 1 sum[r[i]] - sum[l[i]] sum[r[i]] sum r[i] r i sum[l[i]] sum l[i] l i 1 {
					System.out.println(sum[r[i]] - sum[l[i]]);
				} System.out.println(sum[r[i]] - sum[l[i]]) System.out.println System.out System System.out sum[r[i]] - sum[l[i]] sum[r[i]] sum r[i] r i sum[l[i]] sum l[i] l i 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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	}
} 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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	}
} Main
import java.util.*;
import java.lang.*;

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() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	}
}