import java.util.Scanner;

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

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
} Main public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  } main {
    try (Scanner sc = new Scanner(System.in);) {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  } try (Scanner sc = new Scanner(System.in);) {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    } {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc String line = sc.next(); line sc.next() sc.next sc int[] results = new int[n]; results new int[n] n for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      } int i = 0; int i = 0; i 0 i < line.length() - 1 i line.length() - 1 line.length() line.length line 1 i++ i++ i {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      } {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      } if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        } line.charAt(i) == 'A' && line.charAt(i + 1) == 'C' line.charAt(i) == 'A' line.charAt(i) line.charAt line i 'A' line.charAt(i + 1) == 'C' line.charAt(i + 1) line.charAt line i + 1 i 1 'C' {
          results[i + 1] = results[i] + 1;
        } results[i + 1] = results[i] + 1 results[i + 1] results i + 1 i 1 results[i] + 1 results[i] results i 1 {
          results[i + 1] = results[i];
        } results[i + 1] = results[i] results[i + 1] results i + 1 i 1 results[i] results i for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[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(results[r - 1] - results[l - 1]);
      } {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[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(results[r - 1] - results[l - 1]) System.out.println System.out System System.out results[r - 1] - results[l - 1] results[r - 1] results r - 1 r 1 results[l - 1] results l - 1 l 1 String[] args args public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      int n = sc.nextInt();
      int q = sc.nextInt();

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
} Main
import java.util.Scanner;

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

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
}