import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    } main {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc int[] count = new int[N+1]; count new int[N+1] N+1 N 1 boolean flag = false; flag false for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	} {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	} if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		} S.charAt(i) == 'A' S.charAt(i) S.charAt S i 'A' {
    			flag = true;
    			count[i+1] = count[i];
    		} flag = true flag true count[i+1] = count[i] count[i+1] count i+1 i 1 count[i] count i if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		} flag == true && S.charAt(i) == 'C' flag == true flag true S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		} flag = false flag false count[i+1] = count[i] + 1 count[i+1] count i+1 i 1 count[i] + 1 count[i] count i 1 {
    			flag = false;
    			count[i+1] = count[i];
    		} flag = false flag false count[i+1] = count[i] count[i+1] count i+1 i 1 count[i] count i for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	} {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println( count[r] - count[l] ) System.out.println System.out System System.out count[r] - count[l] count[r] count r count[l] count l sc.close() sc.close sc String[] args args public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    }
} public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    }
} Main
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int Q = sc.nextInt();
    	String S = sc.next();
    	
    	int[] count = new int[N+1];
    	boolean flag = false;
    	for( int i = 0; i < N; i++ ) {
    		if( S.charAt(i) == 'A' ) {
    			flag = true;
    			count[i+1] = count[i];
    		}
    		else if( flag == true && S.charAt(i) == 'C' ) {
    			flag = false;
    			count[i+1] = count[i] + 1;
    		}
    		else {
    			flag = false;
    			count[i+1] = count[i];
    		}
    	}

    	for( int i = 0; i < Q; i++ ) {
    		int l = sc.nextInt();
    		int r = sc.nextInt();
    		System.out.println( count[r] - count[l] );
    	}
    	
    	sc.close();
    }
}