import java.util.*;

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[] a=new int[n+1];
    for(int i=0;i<n;i++){
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    }
//    System.out.println(Arrays.toString(a));
    for(int i=0;i<q;i++){
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    }
  }
} import java.util.*; util.* java 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[] a=new int[n+1];
    for(int i=0;i<n;i++){
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    }
//    System.out.println(Arrays.toString(a));
    for(int i=0;i<q;i++){
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    }
  }
} 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[] a=new int[n+1];
    for(int i=0;i<n;i++){
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    }
//    System.out.println(Arrays.toString(a));
    for(int i=0;i<q;i++){
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    }
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int q=sc.nextInt();
    String s=sc.next()+"#";
    int[] a=new int[n+1];
    for(int i=0;i<n;i++){
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    }
//    System.out.println(Arrays.toString(a));
    for(int i=0;i<q;i++){
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    }
  } 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.next sc "#" int[] a=new int[n+1]; a new int[n+1] n+1 n 1 for(int i=0;i<n;i++){
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    } {
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    } a[i+1]=a[i] a[i+1] a i+1 i 1 a[i] a i if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      } s.charAt(i)=='A'&&s.charAt(i+1)=='C' s.charAt(i)=='A' s.charAt(i) s.charAt s i 'A' s.charAt(i+1)=='C' s.charAt(i+1) s.charAt s i+1 i 1 'C' {
        a[i+1]++;
      } a[i+1]++ a[i+1] a i+1 i 1 for(int i=0;i<q;i++){
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    } int i=0; int i=0; i 0 i<q i q i++ i++ i {
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    } {
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    } int f=sc.nextInt(); f sc.nextInt() sc.nextInt sc int t=sc.nextInt(); t sc.nextInt() sc.nextInt sc if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      } a[t]!=a[t-1] a[t] a t a[t-1] a t-1 t 1 {
        System.out.println(a[t]-a[f-1]-1);
      } System.out.println(a[t]-a[f-1]-1) System.out.println System.out System System.out a[t]-a[f-1]-1 a[t]-a[f-1]-1 a[t] a t a[f-1] a f-1 f 1 1 {
        System.out.println(a[t]-a[f-1]);
      } System.out.println(a[t]-a[f-1]) System.out.println System.out System System.out a[t]-a[f-1] a[t] a t a[f-1] a f-1 f 1 String[] args args
import java.util.*;

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[] a=new int[n+1];
    for(int i=0;i<n;i++){
      a[i+1]=a[i];
      if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
        a[i+1]++;
      }
    }
//    System.out.println(Arrays.toString(a));
    for(int i=0;i<q;i++){
      int f=sc.nextInt();
      int t=sc.nextInt();
      if(a[t]!=a[t-1]){
        System.out.println(a[t]-a[f-1]-1);
      }else{
        System.out.println(a[t]-a[f-1]);
      }
    }
  }
}