import 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[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        sc.close();
    }


} import java.util.*; util.* java 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[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        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[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
		int q= sc.nextInt();
      	String s = sc.next();

        int[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        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[] sum = new int[s.length()]; sum new int[s.length()] s.length() s.length s sum[0] = 0 sum[0] sum 0 0 for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        } int i =1; int i =1; i 1 i<n i n i++ i++ i {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        } {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        } if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            } s.charAt(i-1) == 'A' && s.charAt(i) == 'C' s.charAt(i-1) == 'A' s.charAt(i-1) s.charAt s i-1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' {
                sum[i] = sum[i-1] + 1;
            } sum[i] = sum[i-1] + 1 sum[i] sum i sum[i-1] + 1 sum[i-1] sum i-1 i 1 1 {
                sum[i] = sum[i-1];
            } sum[i] = sum[i-1] sum[i] sum i sum[i-1] sum i-1 i 1 for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        } int i =0; int i =0; i 0 i<q i q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int result = sum[r-1] - sum[l-1]; result sum[r-1] - sum[l-1] sum[r-1] sum r-1 r 1 sum[l-1] sum l-1 l 1 System.out.println(result) System.out.println System.out System System.out result 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[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        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[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        sc.close();
    }


} Main
import 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[] sum = new int[s.length()];
        sum[0] = 0;
        for (int i =1; i<n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i-1] + 1;
            }
            else {
                sum[i] = sum[i-1];
            }
        }
                               
        for (int i =0; i<q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            
            int result = sum[r-1] - sum[l-1];
            System.out.println(result);
        }
        sc.close();
    }


}