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 count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  }
} 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 count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  }
} 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 count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = sc.next();
    int count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  } 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 count = 0; count 0 int[] a = new int[n]; a new int[n] n int[] ans = new int[q]; ans new int[q] q for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    } {
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    } if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      } s.charAt(i-1) == 'A' && s.charAt(i) == 'C' s.charAt(i-1) == 'A' s.charAt(i-1) s.charAt s i-1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' {
        count++;
        a[i] = count;
      } count++ count a[i] = count a[i] a i count {
        a[i] = count;
      } a[i] = count a[i] a i count for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    } {
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc ans[i] = a[r-1] - a[l-1] ans[i] ans i a[r-1] - a[l-1] a[r-1] a r-1 r 1 a[l-1] a l-1 l 1 for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      System.out.println(ans[i]);
    } {
      System.out.println(ans[i]);
    } System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i 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 count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  }
} 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 count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  }
} 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 count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  }
}
