import java.util.Scanner;

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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  }

  public void solve(String S, int N, int Q, int[] l, int[] r) {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    }
  }
} import java.util.Scanner; Scanner 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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  }

  public void solve(String S, int N, int Q, int[] l, int[] r) {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  } 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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  } 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 Main abc122C = new Main(); abc122C new Main() abc122C.solve(S, N, Q, l, r) abc122C.solve abc122C S N Q l r String[] args args public void solve(String S, int N, int Q, int[] l, int[] r) {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    }
  } solve {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    }
  } int[] dp = new int[N]; dp new int[N] N for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    } {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    } if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      } 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' {
        dp[i + 1] = dp[i] + 1;
      } dp[i + 1] = dp[i] + 1 dp[i + 1] dp i + 1 i 1 dp[i] + 1 dp[i] dp i 1 {
        dp[i + 1] = dp[i];
      } dp[i + 1] = dp[i] dp[i + 1] dp i + 1 i 1 dp[i] dp i for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    } {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    } System.out.println(dp[r[i]-1] - dp[l[i]-1]) System.out.println System.out System System.out dp[r[i]-1] - dp[l[i]-1] dp[r[i]-1] dp r[i]-1 r[i] r i 1 dp[l[i]-1] dp l[i]-1 l[i] l i 1 String S S int N N int Q Q int[] l l int[] r r 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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  }

  public void solve(String S, int N, int Q, int[] l, int[] r) {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  }

  public void solve(String S, int N, int Q, int[] l, int[] r) {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    }
  }
} Main
import java.util.Scanner;

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();
    }
    Main abc122C = new Main();
    abc122C.solve(S, N, Q, l, r);
  }

  public void solve(String S, int N, int Q, int[] l, int[] r) {
    int[] dp = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i];
      }
    }
    for (int i = 0; i < Q; i++) {
      System.out.println(dp[r[i]-1] - dp[l[i]-1]);
    }
  }
}
