import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  }
} Main public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  } main {
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  } Scanner sc =  new Scanner(System.in); sc new Scanner(System.in) String[] S = sc.nextLine().split(" "); S sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int N = Integer.parseInt(S[0]); N Integer.parseInt(S[0]) Integer.parseInt Integer S[0] S 0 int Q = Integer.parseInt(S[1]); Q Integer.parseInt(S[1]) Integer.parseInt Integer S[1] S 1 String[] T = sc.nextLine().split(""); T sc.nextLine().split("") sc.nextLine().split sc.nextLine() sc.nextLine sc "" int[] val = new int[N]; val new int[N] N int count = 0; count 0 for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    } {
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    } if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      } T[i-1].equals("A") && T[i].equals("C") T[i-1].equals("A") T[i-1].equals T[i-1] T i-1 i 1 "A" T[i].equals("C") T[i].equals T[i] T i "C" {
        count++;
      } count++ count val[i] = count val[i] val i count for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    } {
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    } int a = Integer.parseInt(sc.next())-1; a Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 int b = Integer.parseInt(sc.next())-1; b Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 System.out.println(val[b]-val[a]) System.out.println System.out System System.out val[b]-val[a] val[b] val b val[a] val a String[]args args public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  }
} public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  }
} Main
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int Q = Integer.parseInt(S[1]);
    String[] T = sc.nextLine().split("");
    int[] val = new int[N];
    int count = 0;
    for(int i = 1; i < N; i++){
      if(T[i-1].equals("A") && T[i].equals("C")){
        count++;
      }
      val[i] = count;
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next())-1;
      int b = Integer.parseInt(sc.next())-1;
      System.out.println(val[b]-val[a]);
    }
  }
}