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