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[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	}
	
	
} 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[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	}
	
	
} 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[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	} main {	
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		String s = sc.next();
		int[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	} 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[] map = new int[s.length()+1]; map new int[s.length()+1] s.length()+1 s.length() s.length s 1 int count=0; count 0 for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		} int i=0; int i=0; i 0 i<s.length() i s.length() s.length s i++ i++ i {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		} {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		} if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				} s.charAt(i)=='A'&&i+1<s.length() s.charAt(i)=='A' s.charAt(i) s.charAt s i 'A' i+1<s.length() i+1 i 1 s.length() s.length s if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				} s.charAt(i+1)=='C' s.charAt(i+1) s.charAt s i+1 i 1 'C' {
					count++;
					map[i+1] = map[i] + count;
				} count++ count map[i+1] = map[i] + count map[i+1] map i+1 i 1 map[i] + count map[i] map i count map[i+1] = count map[i+1] map i+1 i 1 count for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		} int i=0; int i=0; i 0 i<q i q i++ i++ i {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		} {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		} int a = Integer.parseInt(sc.next()); a Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int b = Integer.parseInt(sc.next()); b Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc System.out.println(map[b-1]-map[a-1]) System.out.println System.out System System.out map[b-1]-map[a-1] map[b-1] map b-1 b 1 map[a-1] map a-1 a 1 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[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	}
	
	
} 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[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	}
	
	
} Main
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[] map = new int[s.length()+1];
		int count=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A'&&i+1<s.length())
				if(s.charAt(i+1)=='C') {
					count++;
					map[i+1] = map[i] + count;
				}
			map[i+1] = count;
			
		}
		
		
		for(int i=0;i<q;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			System.out.println(map[b-1]-map[a-1]);
		}
		
	}
	
	
}
