import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    }
} Main public static void main(String[] args) {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    } main {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    } try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		} {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int inputN = scan.nextInt(); inputN scan.nextInt() scan.nextInt scan int inputQ = scan.nextInt(); inputQ scan.nextInt() scan.nextInt scan int[] memory = new int[inputN+1]; memory new int[inputN+1] inputN+1 inputN 1 memory[0] = 0 memory[0] memory 0 0 String inputStr = scan.next(); inputStr scan.next() scan.next scan for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			} int n=2; int n=2; n 2 n < inputN+1 n inputN+1 inputN 1 n++ n++ n {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			} {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			} memory[n] = memory[n-1] memory[n] memory n memory[n-1] memory n-1 n 1 if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				} 'A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1)) 'A'==(inputStr.charAt(n-2)) 'A' (inputStr.charAt(n-2)) inputStr.charAt inputStr n-2 n 2 'C'==(inputStr.charAt(n-1)) 'C' (inputStr.charAt(n-1)) inputStr.charAt inputStr n-1 n 1 {
					memory[n]++;
				} memory[n]++ memory[n] memory n List<Integer> ans = new ArrayList<>(); ans new ArrayList<>() for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			} int i = 0; int i = 0; i 0 i < inputQ i inputQ i++ i++ i {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			} {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			} int inputI = scan.nextInt(); inputI scan.nextInt() scan.nextInt scan int inputR = scan.nextInt(); inputR scan.nextInt() scan.nextInt scan ans.add(memory[inputR]-memory[inputI]) ans.add ans memory[inputR]-memory[inputI] memory[inputR] memory inputR memory[inputI] memory inputI for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			} int i = 0; int i = 0; i 0 i < inputQ i inputQ i++ i++ i {
				System.out.println(ans.get(i));
			
			} {
				System.out.println(ans.get(i));
			
			} System.out.println(ans.get(i)) System.out.println System.out System System.out ans.get(i) ans.get ans i String[] args args public class Main {
	public static void main(String[] args) {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    }
} public class Main {
	public static void main(String[] args) {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
         
     try (Scanner scan = new Scanner(System.in)) {
			int inputN = scan.nextInt();
			int inputQ = scan.nextInt();
			int[] memory = new int[inputN+1];
       		memory[0] = 0;
			String inputStr = scan.next();
			
			for(int n=2; n < inputN+1; n++) {
				memory[n] = memory[n-1];
				if('A'==(inputStr.charAt(n-2)) && 'C'==(inputStr.charAt(n-1))) {
					memory[n]++;
				}
			}
			
			List<Integer> ans = new ArrayList<>();
			
			for (int i = 0; i < inputQ; i++) {
				int inputI = scan.nextInt();
				int inputR = scan.nextInt();
				ans.add(memory[inputR]-memory[inputI]);
			}
			
			for (int i = 0; i < inputQ; i++) {
				System.out.println(ans.get(i));
			
			}
		}
    }
}