import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String s = sc.next(); s sc.next() sc.next sc int[] c = new int[n]; c new int[n] n int count = 0; count 0 for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    } int i =0; int i =0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    } {
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    } if ("AC".equals(s.substring(i,i+2))){
        count++;
      } "AC".equals(s.substring(i,i+2)) "AC".equals "AC" s.substring(i,i+2) s.substring s i i+2 i 2 {
        count++;
      } count++ count c[i+1] = count c[i+1] c i+1 i 1 count int l l r r ans; ans StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    } int i = 0; int i = 0; i 0 i<q i q i++ i++ i {
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    } {
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    } l = Integer.parseInt(sc.next()) l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ans = c[r-1]-c[l-1] ans c[r-1]-c[l-1] c[r-1] c r-1 r 1 c[l-1] c l-1 l 1 sb.append(ans) sb.append sb ans sb.append("\n") sb.append sb "\n" System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb sc.close() sc.close sc String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  }
}