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[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 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[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 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[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 1]);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = sc.next();
    int[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 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[] rui = new int[n + 1]; rui new int[n + 1] n + 1 n 1 for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    } {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    } rui[i + 1] = rui[i] rui[i + 1] rui i + 1 i 1 rui[i] rui i if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1; (s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C') (s.charAt(i) == 'A') s.charAt(i) s.charAt s i 'A' (s.charAt(i + 1) == 'C') s.charAt(i + 1) s.charAt s i + 1 i 1 'C' rui[i + 1] = rui[i] + 1 rui[i + 1] rui i + 1 i 1 rui[i] + 1 rui[i] rui i 1 for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 1]);
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 1]);
    } {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 1]);
    } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(rui[r - 1] - rui[l - 1]) System.out.println System.out System System.out rui[r - 1] - rui[l - 1] rui[r - 1] rui r - 1 r 1 rui[l - 1] rui l - 1 l 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[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 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[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 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[] rui = new int[n + 1];
    for(int i = 0; i < n - 1; i++) {
      rui[i + 1] = rui[i];
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) rui[i + 1] = rui[i] + 1;
    }
    for(int i = 0; i < q; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(rui[r - 1] - rui[l - 1]);
    }
  }
}