import java.util.*;
//累積はプログラミングの世界での呼ばれ方
public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  }
} Main public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  } main {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  } Scanner s = new Scanner(System.in); s new Scanner(System.in) int N = s.nextInt(); N s.nextInt() s.nextInt s int Q = s.nextInt(); Q s.nextInt() s.nextInt s String S = s.next(); S s.next() s.next s int[] l1 = new int[Q] l1 new int[Q] Q r1 = new int[Q] r1 new int[Q] Q SR = new int[N]; SR new int[N] N for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    } {
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    } l1[i] = s.nextInt() l1[i] l1 i s.nextInt() s.nextInt s r1[i] = s.nextInt() r1[i] r1 i s.nextInt() s.nextInt s SR[0] = 0 SR[0] SR 0 0 for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[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'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    } {
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    } if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[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' {
        SR[i] = SR[i - 1] + 1;
      } SR[i] = SR[i - 1] + 1 SR[i] SR i SR[i - 1] + 1 SR[i - 1] SR i - 1 i 1 1 {
        SR[i] = SR[i - 1];
      } SR[i] = SR[i - 1] SR[i] SR i SR[i - 1] SR i - 1 i 1 for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    } {
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    } System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]) System.out.println System.out System System.out SR[r1[i] - 1] - SR[l1[i] - 1] SR[r1[i] - 1] SR r1[i] - 1 r1[i] r1 i 1 SR[l1[i] - 1] SR l1[i] - 1 l1[i] l1 i 1 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  }
} Main
import java.util.*;
//累積はプログラミングの世界での呼ばれ方
public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    int Q = s.nextInt();
    String S = s.next();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[N];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i < N; i++){
      if(S.charAt(i - 1) == 'A' && S.charAt(i) == 'C'){
        SR[i] = SR[i - 1] + 1;
      }
      else{
        SR[i] = SR[i - 1];
      }
    }
    /*
    for(int i = 0; i < N; i++) {
      System.out.print(SR[i]);
    }
    */
    //System.out.println("");
    for(int i = 0; i < Q; i++){
      System.out.println(SR[r1[i] - 1] - SR[l1[i] - 1]);
    }
  }
}
