import java.util.Scanner;

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

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  } main {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int Q = scanner.nextInt(); Q scanner.nextInt() scanner.nextInt scanner char[] s = scanner.next().toCharArray(); s scanner.next().toCharArray() scanner.next().toCharArray scanner.next() scanner.next scanner int[] sum = new int[N]; sum new int[N] N for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    } {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    } sum[i] = sum[i - 1] sum[i] sum i sum[i - 1] sum i - 1 i 1 if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++; s[i - 1] == 'A' && s[i] == 'C' s[i - 1] == 'A' s[i - 1] s i - 1 i 1 'A' s[i] == 'C' s[i] s i 'C' sum[i]++ sum[i] sum i StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    } {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    } int l = scanner.nextInt() - 1; l scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 int r = scanner.nextInt() - 1; r scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 sb.append(sum[r] - sum[l]).append('\n') sb.append(sum[r] - sum[l]).append sb.append(sum[r] - sum[l]) sb.append sb sum[r] - sum[l] sum[r] sum r sum[l] sum l '\n' System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  }
} Main
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  }
}
