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[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[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[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[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[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[i]]);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Q = sc.nextInt();
    String S = sc.next();
    int[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[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[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    } {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int[] c = new int[N+1]; c new int[N+1] N+1 N 1 c[1] = 0 c[1] c 1 0 for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    } int i = 1; int i = 1; i 1 i < S.length() i S.length() S.length S i++ i++ i {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    } {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    } char c1 = S.charAt(i-1); c1 S.charAt(i-1) S.charAt S i-1 i 1 char c2 = S.charAt(i); c2 S.charAt(i) S.charAt S i if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      } c1 == 'A' && c2 == 'C' c1 == 'A' c1 'A' c2 == 'C' c2 'C' {
        c[i+1] = c[i] + 1;
      } c[i+1] = c[i] + 1 c[i+1] c i+1 i 1 c[i] + 1 c[i] c i 1 {
        c[i+1] = c[i];
      } c[i+1] = c[i] c[i+1] c i+1 i 1 c[i] c i for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[i]]);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      System.out.println(c[r[i]] - c[l[i]]);
    } {
      System.out.println(c[r[i]] - c[l[i]]);
    } System.out.println(c[r[i]] - c[l[i]]) System.out.println System.out System System.out c[r[i]] - c[l[i]] c[r[i]] c r[i] r i c[l[i]] c l[i] l 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[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[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[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[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[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    
    int[] c = new int[N+1];
    c[1] = 0;
    for (int i = 1; i < S.length(); i++) {
      char c1 = S.charAt(i-1);
      char c2 = S.charAt(i);
      if (c1 == 'A' && c2 == 'C') {
        c[i+1] = c[i] + 1;
      } else {
        c[i+1] = c[i];
      }
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(c[r[i]] - c[l[i]]);
    }
  }
}