import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	}
} 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) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String s = sc.next(); s sc.next() sc.next sc int[] i = new int[n]; i new int[n] n int account = 0; account 0 for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		} int j = 1; int j = 1; j 1 j < s.length() j s.length() s.length s j++ j++ j {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		} {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		} if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			} s.charAt(j-1) == 'A' s.charAt(j-1) s.charAt s j-1 j 1 'A' {
				if(s.charAt(j) == 'C') {
					account++;
				}
			} if(s.charAt(j) == 'C') {
					account++;
				} s.charAt(j) == 'C' s.charAt(j) s.charAt s j 'C' {
					account++;
				} account++ account i[j] = account i[j] i j account List<Integer> res = new ArrayList<Integer>(); res new ArrayList<Integer>() for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		} int j = 0; int j = 0; j 0 j < q j q j++ j++ j {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		} {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		} int start = Integer.parseInt(sc.next()); start Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int end = Integer.parseInt(sc.next()); end Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc res.add(i[end-1] - i[start-1]) res.add res i[end-1] - i[start-1] i[end-1] i end-1 end 1 i[start-1] i start-1 start 1 for(int j : res) {
			System.out.println(j);
		} int j res {
			System.out.println(j);
		} {
			System.out.println(j);
		} System.out.println(j) System.out.println System.out System System.out j String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	}
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		
		String s = sc.next();
		
		int[] i = new int[n];
		
		int account = 0;
		
		for(int j = 1; j < s.length(); j++) {
			if(s.charAt(j-1) == 'A') {
				if(s.charAt(j) == 'C') {
					account++;
				}
			}
			i[j] = account;
		}
		
		List<Integer> res = new ArrayList<Integer>();
		
		for(int j = 0; j < q; j++) {
			int start = Integer.parseInt(sc.next());
			int end = Integer.parseInt(sc.next());

			res.add(i[end-1] - i[start-1]);
		}
		
		for(int j : res) {
			System.out.println(j);
		}
		
	}
}