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[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-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[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-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[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-1]);
    }
  } main {
    //入力
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = sc.next();
    int[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-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[] l = new int[q]; l new int[q] q int[] r = new int[q]; r 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 int[] at = new int[n]; at new int[n] n int t = 0; t 0 for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    } 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')
        ++t;
      at[i] = t;
    } {
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    } if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t; 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' ++t t at[i] = t at[i] at i t for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-1]);
    } int i=0; int i=0; i 0 i<q i q ++i ++i i {
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-1]);
    } {
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-1]);
    } System.out.println(at[r[i]-1] - at[l[i]-1]) System.out.println System.out System System.out at[r[i]-1] - at[l[i]-1] at[r[i]-1] at r[i]-1 r[i] r i 1 at[l[i]-1] at l[i]-1 l[i] l i 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[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-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[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-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[] l = new int[q];
    int[] r = new int[q];
    for(int i=0; i<q; i++){
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    //右隣がCであるようなAを数える
    int[] at = new int[n];
    int t = 0;
    for(int i=1; i<n; ++i){
      if(s.charAt(i-1) == 'A' & s.charAt(i) == 'C')
        ++t;
      at[i] = t;
    }

    //lからrの間に'AC'があるかどうか調べる
    for(int i=0; i<q; ++i){
      //at[i個目のr] - at[i個目のl]
      System.out.println(at[r[i]-1] - at[l[i]-1]);
    }
  }
}
