import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  }
} import java.io.*; io.* java public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  } main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] line1 = br.readLine().split(" "); line1 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(line1[0]); n Integer.parseInt(line1[0]) Integer.parseInt Integer line1[0] line1 0 int q = Integer.parseInt(line1[1]); q Integer.parseInt(line1[1]) Integer.parseInt Integer line1[1] line1 1 int[] numAC = new int[n]; numAC new int[n] n char[] s = br.readLine().toCharArray(); s br.readLine().toCharArray() br.readLine().toCharArray br.readLine() br.readLine br boolean a = false; a false boolean c = false; c false int sum = 0; sum 0 for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    } {
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    } c = s[i] == 'C' c s[i] == 'C' s[i] s i 'C' if (a && c) sum++; a && c a c sum++ sum a = s[i] == 'A' a s[i] == 'A' s[i] s i 'A' numAC[i] = sum numAC[i] numAC i sum StringBuilder result = new StringBuilder(); result new StringBuilder() int l; l int r; r String[] question; question for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    } int i=0; int i=0; i 0 i<q i q i++ i++ i {
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    } {
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    } question = br.readLine().split(" ") question br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " l = Integer.parseInt(question[0]) l Integer.parseInt(question[0]) Integer.parseInt Integer question[0] question 0 r = Integer.parseInt(question[1]) r Integer.parseInt(question[1]) Integer.parseInt Integer question[1] question 1 result.append(numAC[r-1]-numAC[l-1]) result.append result numAC[r-1]-numAC[l-1] numAC[r-1] numAC r-1 r 1 numAC[l-1] numAC l-1 l 1 result.append("\n") result.append result "\n" System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  }
} Main
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  }
}
