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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  }

} 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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  }

} 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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  } 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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  } 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 sc.close() sc.close sc String[] s = S.split(""); s S.split("") S.split S "" int[] ac = new int[N+1]; ac new int[N+1] N+1 N 1 ac[0] = 0 ac[0] ac 0 0 ac[1] = 0 ac[1] ac 1 0 for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    } {
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    } if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      } s[i-1].equals("A") && s[i].equals("C") s[i-1].equals("A") s[i-1].equals s[i-1] s i-1 i 1 "A" s[i].equals("C") s[i].equals s[i] s i "C" {
        ac[i+1] = ac[i] + 1; 
      } ac[i+1] = ac[i] + 1 ac[i+1] ac i+1 i 1 ac[i] + 1 ac[i] ac i 1 {
        ac[i+1] = ac[i];
      } ac[i+1] = ac[i] ac[i+1] ac i+1 i 1 ac[i] ac i for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      System.out.println(ac[r[i]] - ac[l[i]]);
    } {
      System.out.println(ac[r[i]] - ac[l[i]]);
    } System.out.println(ac[r[i]] - ac[l[i]]) System.out.println System.out System System.out ac[r[i]] - ac[l[i]] ac[r[i]] ac r[i] r i ac[l[i]] ac l[i] l i 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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  }

} 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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  }

} 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();
    }

    sc.close();

    String[] s = S.split("");

    int[] ac = new int[N+1];
    
    ac[0] = 0;
    ac[1] = 0;

    for (int i = 1; i < N; i++){
      if (s[i-1].equals("A") && s[i].equals("C")) {
        ac[i+1] = ac[i] + 1; 
      } else {
        ac[i+1] = ac[i];
      }
    }

    for (int i = 0; i < Q; i++){
      System.out.println(ac[r[i]] - ac[l[i]]);
    }

  }

}