import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String str = sc.next(); str sc.next() sc.next sc char[] ch = new char[n]; ch new char[n] n int[] dp = new int[n]; dp new int[n] n dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      ch[i] = str.charAt(i);
    } {
      ch[i] = str.charAt(i);
    } ch[i] = str.charAt(i) ch[i] ch i str.charAt(i) str.charAt str i for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    } {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    } if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i]; ch[i] == 'A' && ch[i+1] == 'C' ch[i] == 'A' ch[i] ch i 'A' ch[i+1] == 'C' ch[i+1] ch i+1 i 1 'C' dp[i+1] = dp[i] + 1 dp[i+1] dp i+1 i 1 dp[i] + 1 dp[i] dp i 1 dp[i+1] = dp[i] dp[i+1] dp i+1 i 1 dp[i] dp i int l l r r ans; ans for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    } {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    } ans = 0 ans 0 l = Integer.parseInt(sc.next()) l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ans = dp[r-1] - dp[l-1] ans dp[r-1] - dp[l-1] dp[r-1] dp r-1 r 1 dp[l-1] dp l-1 l 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[n];
    int[] dp = new int[n];
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
      ch[i] = str.charAt(i);
    }
    for(int i = 0; i < n - 1; i++) {
      if(ch[i] == 'A' && ch[i+1] == 'C') dp[i+1] = dp[i] + 1;
      else dp[i+1] = dp[i];
    }
    int l , r, ans;
    for(int i = 0; i < q; i++) {
      ans = 0;
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = dp[r-1] - dp[l-1];
      System.out.println(ans);
    }
  }
}
