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[] prefixCnt = new int[n];
      for(int i = 1; i < prefixCnt.length; i++) {
        if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A')
          prefixCnt[i] = prefixCnt[i-1] + 1;
        else
          prefixCnt[i] = prefixCnt[i-1];
      }

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

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

      for(int i = 0; i < q; i++) 
        System.out.println(-prefixCnt[sc.nextInt()-1] + prefixCnt[sc.nextInt()-1]);
  } main { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int q = sc.nextInt();

      String s = sc.next();
      int[] prefixCnt = new int[n];
      for(int i = 1; i < prefixCnt.length; i++) {
        if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A')
          prefixCnt[i] = prefixCnt[i-1] + 1;
        else
          prefixCnt[i] = prefixCnt[i-1];
      }

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

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

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

      for(int i = 0; i < q; i++) 
        System.out.println(-prefixCnt[sc.nextInt()-1] + prefixCnt[sc.nextInt()-1]);
  }
}