import java.util.ArrayList;
import java.util.Scanner;

class Main {

  static final int INF = Integer.MAX_VALUE / 4;

  static int cntAC(ArrayList<Integer> list, int l, int r) {
    int idx_l;
    int idx_r;
    // FOR LEFT lの右のindexを求める
    int ok = list.size();
    int ng = 0;
    int mid = (ok + ng) / 2;
    while (ok - ng > 1) {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_l = ok;
    // FOR RIGHT rの左のindexを求める
    ok = 0;
    ng = list.size();
    mid = (ok + ng) / 2;
    while (ng - ok > 1) {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_r = ok;
    if (idx_r - idx_l < 0) {
      return 0;
    }
    return idx_r - idx_l + 1;
  }

  static ArrayList<Integer> searchAC(String s) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(-INF);
    for (int i = 0; i < s.length() - 1;) {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    }
    list.add(INF);
    return list;
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int Q = Integer.parseInt(scanner.next());
    String s = scanner.next();
    int[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    }
    scanner.close();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list = searchAC(s);

    //System.out.println(list);

    for (int i = 0; i < Q; i++) {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    }

  }

} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main {

  static final int INF = Integer.MAX_VALUE / 4;

  static int cntAC(ArrayList<Integer> list, int l, int r) {
    int idx_l;
    int idx_r;
    // FOR LEFT lの右のindexを求める
    int ok = list.size();
    int ng = 0;
    int mid = (ok + ng) / 2;
    while (ok - ng > 1) {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_l = ok;
    // FOR RIGHT rの左のindexを求める
    ok = 0;
    ng = list.size();
    mid = (ok + ng) / 2;
    while (ng - ok > 1) {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_r = ok;
    if (idx_r - idx_l < 0) {
      return 0;
    }
    return idx_r - idx_l + 1;
  }

  static ArrayList<Integer> searchAC(String s) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(-INF);
    for (int i = 0; i < s.length() - 1;) {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    }
    list.add(INF);
    return list;
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int Q = Integer.parseInt(scanner.next());
    String s = scanner.next();
    int[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    }
    scanner.close();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list = searchAC(s);

    //System.out.println(list);

    for (int i = 0; i < Q; i++) {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    }

  }

} Main static final int INF = Integer.MAX_VALUE / 4; INF Integer.MAX_VALUE / 4 Integer.MAX_VALUE Integer Integer.MAX_VALUE 4 static int cntAC(ArrayList<Integer> list, int l, int r) {
    int idx_l;
    int idx_r;
    // FOR LEFT lの右のindexを求める
    int ok = list.size();
    int ng = 0;
    int mid = (ok + ng) / 2;
    while (ok - ng > 1) {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_l = ok;
    // FOR RIGHT rの左のindexを求める
    ok = 0;
    ng = list.size();
    mid = (ok + ng) / 2;
    while (ng - ok > 1) {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_r = ok;
    if (idx_r - idx_l < 0) {
      return 0;
    }
    return idx_r - idx_l + 1;
  } cntAC {
    int idx_l;
    int idx_r;
    // FOR LEFT lの右のindexを求める
    int ok = list.size();
    int ng = 0;
    int mid = (ok + ng) / 2;
    while (ok - ng > 1) {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_l = ok;
    // FOR RIGHT rの左のindexを求める
    ok = 0;
    ng = list.size();
    mid = (ok + ng) / 2;
    while (ng - ok > 1) {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_r = ok;
    if (idx_r - idx_l < 0) {
      return 0;
    }
    return idx_r - idx_l + 1;
  } int idx_l; idx_l int idx_r; idx_r int ok = list.size(); ok list.size() list.size list int ng = 0; ng 0 int mid = (ok + ng) / 2; mid (ok + ng) / 2 (ok + ng) ok ng 2 while (ok - ng > 1) {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    } ok - ng > 1 ok - ng ok ng 1 {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    } if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      } list.get(mid) < l list.get(mid) list.get list mid l {
        ng = mid;
      } ng = mid ng mid {
        ok = mid;
      } ok = mid ok mid mid = (ok + ng) / 2 mid (ok + ng) / 2 (ok + ng) ok ng 2 idx_l = ok idx_l ok ok = 0 ok 0 ng = list.size() ng list.size() list.size list mid = (ok + ng) / 2 mid (ok + ng) / 2 (ok + ng) ok ng 2 while (ng - ok > 1) {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    } ng - ok > 1 ng - ok ng ok 1 {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    } if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      } list.get(mid) <= r list.get(mid) list.get list mid r {
        ok = mid;
      } ok = mid ok mid {
        ng = mid;
      } ng = mid ng mid mid = (ok + ng) / 2 mid (ok + ng) / 2 (ok + ng) ok ng 2 idx_r = ok idx_r ok if (idx_r - idx_l < 0) {
      return 0;
    } idx_r - idx_l < 0 idx_r - idx_l idx_r idx_l 0 {
      return 0;
    } return 0; 0 return idx_r - idx_l + 1; idx_r - idx_l + 1 idx_r - idx_l idx_r idx_l 1 ArrayList<Integer> list list int l l int r r static ArrayList<Integer> searchAC(String s) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(-INF);
    for (int i = 0; i < s.length() - 1;) {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    }
    list.add(INF);
    return list;
  } searchAC {
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(-INF);
    for (int i = 0; i < s.length() - 1;) {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    }
    list.add(INF);
    return list;
  } ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() list.add(-INF) list.add list -INF INF for (int i = 0; i < s.length() - 1;) {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    } int i = 0; int i = 0; i 0 i < s.length() - 1 i s.length() - 1 s.length() s.length s 1 {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    } {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    } if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      } 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' {
        list.add(i);
        i = i + 2;
      } list.add(i) list.add list i i = i + 2 i i + 2 i 2 {
        i = i + 1;
      } i = i + 1 i i + 1 i 1 list.add(INF) list.add list INF return list; list String s s public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int Q = Integer.parseInt(scanner.next());
    String s = scanner.next();
    int[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    }
    scanner.close();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list = searchAC(s);

    //System.out.println(list);

    for (int i = 0; i < Q; i++) {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    }

  } main {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int Q = Integer.parseInt(scanner.next());
    String s = scanner.next();
    int[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    }
    scanner.close();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list = searchAC(s);

    //System.out.println(list);

    for (int i = 0; i < Q; i++) {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    }

  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = Integer.parseInt(scanner.next()); N Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int Q = Integer.parseInt(scanner.next()); Q Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner String s = scanner.next(); s scanner.next() scanner.next scanner 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] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    } {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    } l[i] = Integer.parseInt(scanner.next()) l[i] l i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner r[i] = Integer.parseInt(scanner.next()) r[i] r i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner scanner.close() scanner.close scanner ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() list = searchAC(s) list searchAC(s) searchAC s for (int i = 0; i < Q; i++) {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    } {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    } System.out.println(cntAC(list, l[i] - 1, r[i] - 2)) System.out.println System.out System System.out cntAC(list, l[i] - 1, r[i] - 2) cntAC list l[i] - 1 l[i] l i 1 r[i] - 2 r[i] r i 2 String[] args args
import java.util.ArrayList;
import java.util.Scanner;

class Main {

  static final int INF = Integer.MAX_VALUE / 4;

  static int cntAC(ArrayList<Integer> list, int l, int r) {
    int idx_l;
    int idx_r;
    // FOR LEFT lの右のindexを求める
    int ok = list.size();
    int ng = 0;
    int mid = (ok + ng) / 2;
    while (ok - ng > 1) {
      if (list.get(mid) < l) {
        ng = mid;
      } else {
        ok = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_l = ok;
    // FOR RIGHT rの左のindexを求める
    ok = 0;
    ng = list.size();
    mid = (ok + ng) / 2;
    while (ng - ok > 1) {
      if (list.get(mid) <= r) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    }
    idx_r = ok;
    if (idx_r - idx_l < 0) {
      return 0;
    }
    return idx_r - idx_l + 1;
  }

  static ArrayList<Integer> searchAC(String s) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(-INF);
    for (int i = 0; i < s.length() - 1;) {
      if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
        list.add(i);
        i = i + 2;
      } else {
        i = i + 1;
      }
    }
    list.add(INF);
    return list;
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int Q = Integer.parseInt(scanner.next());
    String s = scanner.next();
    int[] l = new int[Q];
    int[] r = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = Integer.parseInt(scanner.next());
      r[i] = Integer.parseInt(scanner.next());
    }
    scanner.close();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list = searchAC(s);

    //System.out.println(list);

    for (int i = 0; i < Q; i++) {
      System.out.println(cntAC(list, l[i] - 1, r[i] - 2));
    }

  }

}
