import 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[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  }
  
} import java.util.*; util.* java 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[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  }
  
} 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[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Q = sc.nextInt();
    String S = sc.next();
    int[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  } 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[] numArray = new int[N]; numArray new int[N] N int count = 0; count 0 numArray[0] = 0 numArray[0] numArray 0 0 for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    } {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    } if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        } S.substring(i,i+1).equals("A") S.substring(i,i+1).equals S.substring(i,i+1) S.substring S i i+1 i 1 "A" {
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        } if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            } i < N-1 && S.substring(i+1,i+2).equals("C") i < N-1 i N-1 N 1 S.substring(i+1,i+2).equals("C") S.substring(i+1,i+2).equals S.substring(i+1,i+2) S.substring S i+1 i 1 i+2 i 2 "C" {
                count++;
            } count++ count numArray[i+1] = count numArray[i+1] numArray i+1 i 1 count for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    } int j = 0; int j = 0; j 0 j < Q j Q j++ j++ j {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    } {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    } int start = sc.nextInt(); start sc.nextInt() sc.nextInt sc int end = sc.nextInt(); end sc.nextInt() sc.nextInt sc int answer = numArray[end-1] - numArray[start-1]; answer numArray[end-1] - numArray[start-1] numArray[end-1] numArray end-1 end 1 numArray[start-1] numArray start-1 start 1 System.out.println(answer) System.out.println System.out System System.out answer String[] args args 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[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  }
  
} 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[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  }
  
} Main
import 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[] numArray = new int[N];
    int count = 0;
    numArray[0] = 0;
    for (int i = 0; i < N-1; i++) {
        if (S.substring(i,i+1).equals("A")){
            if (i < N-1 && S.substring(i+1,i+2).equals("C")){
                count++;
            }
        }
        numArray[i+1] = count;
    }
    for (int j = 0; j < Q; j++) {
        int start = sc.nextInt();
        int end = sc.nextInt();
        int answer = numArray[end-1] - numArray[start-1];
        System.out.println(answer);
    }
  }
  
}
