import java.util.Scanner;

public class Main{
    static int[] A,L,R;
    static int N,Q;
    static String str;
    static int ans;
    public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    }

} import java.util.Scanner; Scanner java.util public class Main{
    static int[] A,L,R;
    static int N,Q;
    static String str;
    static int ans;
    public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    }

} Main static int[] A A L L R; R static int N N Q; Q static String str; str static int ans; ans public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    } main {
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc Q = sc.nextInt() Q sc.nextInt() sc.nextInt sc str = sc.next() str sc.next() sc.next sc A = new int[N] A new int[N] N R = new int[Q] R new int[Q] Q L = new int[Q] L new int[Q] Q for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      } {
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      } L[i]=sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i]=sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc A[0]=0 A[0] A 0 0 if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      } str.charAt(0)=='A' && str.charAt(1)=='C' str.charAt(0)=='A' str.charAt(0) str.charAt str 0 'A' str.charAt(1)=='C' str.charAt(1) str.charAt str 1 'C' {
        A[1]=1;
      } A[1]=1 A[1] A 1 1 {
        A[1]=0;
      } A[1]=0 A[1] A 1 0 for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      } int i=2; int i=2; i 2 i<N i N i++ i++ i {
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      } {
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      } if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        } str.charAt(i-1)=='A' && str.charAt(i)=='C' str.charAt(i-1)=='A' str.charAt(i-1) str.charAt str i-1 i 1 'A' str.charAt(i)=='C' str.charAt(i) str.charAt str i 'C' {
          A[i]=A[i-1]+1;
        } A[i]=A[i-1]+1 A[i] A i A[i-1]+1 A[i-1] A i-1 i 1 1 {
          A[i]=A[i-1];
        } A[i]=A[i-1] A[i] A i A[i-1] A i-1 i 1 for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      } {
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      } ans = A[R[i]-1]-A[L[i]-1] ans A[R[i]-1]-A[L[i]-1] A[R[i]-1] A R[i]-1 R[i] R i 1 A[L[i]-1] A L[i]-1 L[i] L i 1 System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main{
    static int[] A,L,R;
    static int N,Q;
    static String str;
    static int ans;
    public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    }

} public class Main{
    static int[] A,L,R;
    static int N,Q;
    static String str;
    static int ans;
    public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    }

} Main
import java.util.Scanner;

public class Main{
    static int[] A,L,R;
    static int N,Q;
    static String str;
    static int ans;
    public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      N = sc.nextInt();
      Q = sc.nextInt();
      str = sc.next();
      A = new int[N];
      R = new int[Q];
      L = new int[Q];
      for(int i=0;i<Q;i++){
        L[i]=sc.nextInt();
        R[i]=sc.nextInt();
      }
      A[0]=0;
      if(str.charAt(0)=='A' && str.charAt(1)=='C'){
        A[1]=1;
      }
      else{
        A[1]=0;
      }
      for(int i=2;i<N;i++){
        if(str.charAt(i-1)=='A' && str.charAt(i)=='C'){
          A[i]=A[i-1]+1;
        }
        else{
          A[i]=A[i-1];
        }
      }
      for(int i=0;i<Q;i++){
        ans = A[R[i]-1]-A[L[i]-1];
        System.out.println(ans);
      }
    }

}