import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

  public static void main (String[] args) {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {

  public static void main (String[] args) {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  }
} Main public static void main (String[] args) {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  } main {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  } String[] nq = new String[2]; nq new String[2] 2 char[] s = null; s null List<String[]> lr = new ArrayList<>(); lr new ArrayList<>() try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    } IOException e {
      e.printStackTrace();
      System.exit(1);
    } e.printStackTrace() e.printStackTrace e System.exit(1) System.exit System 1 {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) nq = br.readLine().split("\\s") nq br.readLine().split("\\s") br.readLine().split br.readLine() br.readLine br "\\s" s = br.readLine().toCharArray() s br.readLine().toCharArray() br.readLine().toCharArray br.readLine() br.readLine br for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      } int i = 0; int i = 0; i 0 i < Integer.parseInt(nq[1]) i Integer.parseInt(nq[1]) Integer.parseInt Integer nq[1] nq 1 i++ i++ i {
        lr.add(br.readLine().split("\\s"));
      } {
        lr.add(br.readLine().split("\\s"));
      } lr.add(br.readLine().split("\\s")) lr.add lr br.readLine().split("\\s") br.readLine().split br.readLine() br.readLine br "\\s" int[] sum = new int[s.length + 1]; sum new int[s.length + 1] s.length + 1 s.length s s.length 1 for (int i = 1; i < s.length; i++) {
      if (s[i-1] == 'A' && s[i] == 'C') {
        sum[i+1] = sum[i] + 1;
      } else {
        sum[i+1] = sum[i];
      }
    } int i = 1; int i = 1; i 1 i < s.length i s.length s s.length i++ i++ i {
      if (s[i-1] == 'A' && s[i] == 'C') {
        sum[i+1] = sum[i] + 1;
      } else {
        sum[i+1] = sum[i];
      }
    } {
      if (s[i-1] == 'A' && s[i] == 'C') {
        sum[i+1] = sum[i] + 1;
      } else {
        sum[i+1] = sum[i];
      }
    } if (s[i-1] == 'A' && s[i] == 'C') {
        sum[i+1] = sum[i] + 1;
      } else {
        sum[i+1] = 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+1] = sum[i] + 1;
      } sum[i+1] = sum[i] + 1 sum[i+1] sum i+1 i 1 sum[i] + 1 sum[i] sum i 1 {
        sum[i+1] = sum[i];
      } sum[i+1] = sum[i] sum[i+1] sum i+1 i 1 sum[i] sum i for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    } String[] array lr {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    } {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    } final int start = Integer.parseInt(array[0]); start Integer.parseInt(array[0]) Integer.parseInt Integer array[0] array 0 final int end = Integer.parseInt(array[1]); end Integer.parseInt(array[1]) Integer.parseInt Integer array[1] array 1 System.out.println(sum[end] - sum[start]) System.out.println System.out System System.out sum[end] - sum[start] sum[end] sum end sum[start] sum start String[] args args public class Main {

  public static void main (String[] args) {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  }
} public class Main {

  public static void main (String[] args) {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

  public static void main (String[] args) {
    String[] nq = new String[2];
    char[] s = null;
    List<String[]> lr = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      nq = br.readLine().split("\\s");
      s = br.readLine().toCharArray();
      for (int i = 0; i < Integer.parseInt(nq[1]); i++) {
        lr.add(br.readLine().split("\\s"));
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

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

    for (String[] array : lr) {
      final int start = Integer.parseInt(array[0]);
      final int end = Integer.parseInt(array[1]);
      System.out.println(sum[end] - sum[start]);
    }
  }
}
