import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	}
} import java.util.*; util.* java public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	}
} Main public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	} Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) int L = keyboard.nextInt(); L keyboard.nextInt() keyboard.nextInt keyboard int Q = keyboard.nextInt(); Q keyboard.nextInt() keyboard.nextInt keyboard String N = keyboard.next(); N keyboard.next() keyboard.next keyboard String[]moji = N.split(""); moji N.split("") N.split N "" int[]wa = new int[L+1]; wa new int[L+1] L+1 L 1 for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		} int i = 0; int i = 0; i 0 i<L-1 i L-1 L 1 i++ i++ i {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		} {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		} if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			} moji[i].equals("A") moji[i].equals moji[i] moji i "A" {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			} if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				} moji[i+1].equals("C") moji[i+1].equals moji[i+1] moji i+1 i 1 "C" {
					wa[i+2] = 1;
				} wa[i+2] = 1 wa[i+2] wa i+2 i 2 1 for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		} int j = 1; int j = 1; j 1 j<L+1 j L+1 L 1 j++ j++ j {
			wa[j] = wa[j] + wa[j-1];
		} {
			wa[j] = wa[j] + wa[j-1];
		} wa[j] = wa[j] + wa[j-1] wa[j] wa j wa[j] + wa[j-1] wa[j] wa j wa[j-1] wa j-1 j 1 for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		} int k = 0; int k = 0; k 0 k<Q k Q k++ k++ k {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		} {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		} int a = keyboard.nextInt(); a keyboard.nextInt() keyboard.nextInt keyboard int b = keyboard.nextInt(); b keyboard.nextInt() keyboard.nextInt keyboard if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			} a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A") a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A") a != 1 a 1 moji[a-1].equals("C") moji[a-1].equals moji[a-1] moji a-1 a 1 "C" moji[a-2].equals("A") moji[a-2].equals moji[a-2] moji a-2 a 2 "A" {
				System.out.println(wa[b]- wa[a-1]-1);
			} System.out.println(wa[b]- wa[a-1]-1) System.out.println System.out System System.out wa[b]- wa[a-1]-1 wa[b]- wa[a-1]-1 wa[b] wa b wa[a-1] wa a-1 a 1 1 {
				System.out.println(wa[b]- wa[a-1]);
			} System.out.println(wa[b]- wa[a-1]) System.out.println System.out System System.out wa[b]- wa[a-1] wa[b] wa b wa[a-1] wa a-1 a 1 keyboard.close() keyboard.close keyboard String[] args args public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	}
} public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	}
} Main
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int L = keyboard.nextInt();
		int Q = keyboard.nextInt();
		String N = keyboard.next();
		
		String[]moji = N.split("");
		int[]wa = new int[L+1];
		
		for(int i = 0; i<L-1; i++) {
			if(moji[i].equals("A")) {
				if(moji[i+1].equals("C")) {
					wa[i+2] = 1;
				}
			}
		}
		
		for(int j = 1; j<L+1; j++) {
			wa[j] = wa[j] + wa[j-1];
		}
		
		for(int k = 0; k<Q; k++) {
			int a = keyboard.nextInt();
			int b = keyboard.nextInt();
			if(a != 1 && moji[a-1].equals("C") && moji[a-2].equals("A")) {
				System.out.println(wa[b]- wa[a-1]-1);
			}else{
				System.out.println(wa[b]- wa[a-1]);
			}
		}
		keyboard.close();	
	}
}
