import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	}

} import java.util.Map.Entry; Entry java.util.Map import java.util.Scanner; Scanner java.util import java.util.TreeMap; TreeMap java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	}

} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	} main {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in String s = in.next(); s in.next() in.next in TreeMap<Integer, Integer> ml = new TreeMap<>(); ml new TreeMap<>() int idx = 0; idx 0 int d = 0; d 0 while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		} true {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		} idx = s.indexOf("AC", idx) idx s.indexOf("AC", idx) s.indexOf s "AC" idx if (idx == -1) {
				break;
			} idx == -1 idx -1 1 {
				break;
			} break; ml.put(idx, ++d) ml.put ml idx ++d d idx++ idx for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		} {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		} int l = in.nextInt() - 1; l in.nextInt() - 1 in.nextInt() in.nextInt in 1 int r = in.nextInt() - 1; r in.nextInt() - 1 in.nextInt() in.nextInt in 1 int c = d; c d if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			} l != 0 l 0 {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			} Entry<Integer, Integer> lower = ml.lowerEntry(l); lower ml.lowerEntry(l) ml.lowerEntry ml l if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				} lower != null lower null {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				} c -= lower.getValue() c lower.getValue() lower.getValue lower if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			} r != n r n {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			} Entry<Integer, Integer> ceil = ml.ceilingEntry(r); ceil ml.ceilingEntry(r) ml.ceilingEntry ml r if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				} ceil != null ceil null {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				} c -= (d - ceil.getValue() + 1) c (d - ceil.getValue() + 1) d - ceil.getValue() d ceil.getValue() ceil.getValue ceil 1 System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	}

} Main
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		
		TreeMap<Integer, Integer> ml = new TreeMap<>();
		//TreeMap<Integer, Integer> mr = new TreeMap<>();
		//int[] a = new int[q];
		int idx = 0;
		int d = 0;
		while (true) {
			idx = s.indexOf("AC", idx);
			if (idx == -1) {
				break;
			}
			ml.put(idx, ++d);
			idx++;
		}

		for (int i = 0; i < q; i++) {
//			System.out.println("----");
//			System.out.println(i);
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int c = d;
//			System.out.println(c);
			if (l != 0) {
				Entry<Integer, Integer> lower = ml.lowerEntry(l);
				if (lower != null) {
//					System.out.println("L " + lower.getValue());
					c -= lower.getValue();
				}
			}
			if (r != n) {
				Entry<Integer, Integer> ceil = ml.ceilingEntry(r);
				if (ceil != null) {
//					System.out.println("R " + ceil.getValue());
//					System.out.println("R' " + (d - ceil.getValue() + 1));
					c -= (d - ceil.getValue() + 1);
				}
			}
			System.out.println(c);
		}
	}

}
