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[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  }
} 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[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  }
} 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[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Q = sc.nextInt();
    String S = sc.next();
    int[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  } 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[] ls = new int[Q]; ls new int[Q] Q int[] rs = new int[Q]; rs new int[Q] Q for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    } {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    } ls[i] = sc.nextInt() ls[i] ls i sc.nextInt() sc.nextInt sc rs[i] = sc.nextInt() rs[i] rs i sc.nextInt() sc.nextInt sc int[] ruisekiwa = new int[N]; ruisekiwa new int[N] N int ruiseki = 0; ruiseki 0 for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    } {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    } if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++; 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' ruiseki++ ruiseki ruisekiwa[i] = ruiseki ruisekiwa[i] ruisekiwa i ruiseki for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    } {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    } if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0); ls[i] > 1 ls[i] ls i 1 System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]) System.out.println System.out System System.out ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2] ruisekiwa[rs[i]-2] ruisekiwa rs[i]-2 rs[i] rs i 2 ruisekiwa[ls[i]-2] ruisekiwa ls[i]-2 ls[i] ls i 2 System.out.println(ruisekiwa[rs[i]-2] - 0) System.out.println System.out System System.out ruisekiwa[rs[i]-2] - 0 ruisekiwa[rs[i]-2] ruisekiwa rs[i]-2 rs[i] rs i 2 0 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[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  }
} 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[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  }
} 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[] ls = new int[Q];
    int[] rs = new int[Q];
    for (int i = 0; i < Q; i++) {
      ls[i] = sc.nextInt();
      rs[i] = sc.nextInt();
    }
    
    int[] ruisekiwa = new int[N];
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C')
        ruiseki++;
      ruisekiwa[i] = ruiseki;
    }
    
   
    for (int i = 0; i < Q; i++) {
      if (ls[i] > 1)
      	System.out.println(ruisekiwa[rs[i]-2] - ruisekiwa[ls[i]-2]);
      else
        System.out.println(ruisekiwa[rs[i]-2] - 0);
    }
    
  }
}
