import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int acCount[] = new int[N];
    int Q = sc.nextInt();
    String S = sc.next();
    String s[] = S.split("");
    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();
    }

    for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    }
    //System.out.println(Arrays.toString(acCount));
  }
} import java.util.*; util.* java class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int acCount[] = new int[N];
    int Q = sc.nextInt();
    String S = sc.next();
    String s[] = S.split("");
    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();
    }

    for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    }
    //System.out.println(Arrays.toString(acCount));
  }
} Main public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int acCount[] = new int[N];
    int Q = sc.nextInt();
    String S = sc.next();
    String s[] = S.split("");
    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();
    }

    for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    }
    //System.out.println(Arrays.toString(acCount));
  } main {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int acCount[] = new int[N];
    int Q = sc.nextInt();
    String S = sc.next();
    String s[] = S.split("");
    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();
    }

    for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    }
    //System.out.println(Arrays.toString(acCount));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int acCount[] = new int[N]; acCount new int[N] N int Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc String s[] = S.split(""); s S.split("") S.split S "" 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 for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    } {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    } if (i > 0) {
        acCount[i] = acCount[i-1];
      } i > 0 i 0 {
        acCount[i] = acCount[i-1];
      } acCount[i] = acCount[i-1] acCount[i] acCount i acCount[i-1] acCount i-1 i 1 if (i >= N-1) {
        break;
      } i >= N-1 i N-1 N 1 {
        break;
      } break; if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[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' {
        acCount[i] += 1;
      } acCount[i] += 1 acCount[i] acCount i 1 for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    } {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    } int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1; ans acCount[r[i]-1] - acCount[l[i]-1] + 1 acCount[r[i]-1] - acCount[l[i]-1] acCount[r[i]-1] acCount r[i]-1 r[i] r i 1 acCount[l[i]-1] acCount l[i]-1 l[i] l i 1 1 if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      } l[i]-1 > 0 l[i]-1 l[i] l i 1 0 {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      } if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        } acCount[l[i]-1] == acCount[l[i]-2] acCount[l[i]-1] acCount l[i]-1 l[i] l i 1 acCount[l[i]-2] acCount l[i]-2 l[i] l i 2 {
          ans--;
        } ans-- ans if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      } !(S.charAt(0) == 'A' && S.charAt(1) == 'C') (S.charAt(0) == 'A' && S.charAt(1) == 'C') S.charAt(0) == 'A' S.charAt(0) S.charAt S 0 'A' S.charAt(1) == 'C' S.charAt(1) S.charAt S 1 'C' {
        ans--;
      } ans-- ans if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      } r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1] r[i] < S.length() r[i] r i S.length() S.length S acCount[r[i]-2] != acCount[r[i]-1] acCount[r[i]-2] acCount r[i]-2 r[i] r i 2 acCount[r[i]-1] acCount r[i]-1 r[i] r i 1 {
        ans--;
      } ans-- ans System.out.println(ans) System.out.println System.out System System.out ans String args[] args
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int acCount[] = new int[N];
    int Q = sc.nextInt();
    String S = sc.next();
    String s[] = S.split("");
    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();
    }

    for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    }
    //System.out.println(Arrays.toString(acCount));
  }
}
