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[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  }
} 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[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  } 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[] line = sc.next().split(""); line sc.next().split("") sc.next().split sc.next() sc.next sc "" int[] nums = new int[n]; nums new int[n] n boolean flg = false; flg false int current = 0; current 0 for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    } {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    } if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      } flg && "C".equals(line[i]) flg "C".equals(line[i]) "C".equals "C" line[i] line i {
        current++;
        flg = false;
      } current++ current flg = false flg false if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      } "A".equals(line[i]) "A".equals "A" line[i] line i {
        flg = true;
      } flg = true flg true {
        flg = false;
      } flg = false flg false nums[i] = current nums[i] nums i current for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    } {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    } int a = sc.nextInt() - 1; a sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int b = sc.nextInt() - 1; b sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 System.out.println(nums[b] - nums[a]) System.out.println System.out System System.out nums[b] - nums[a] nums[b] nums b nums[a] nums a 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[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  }
} 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[] line = sc.next().split("");
    int[] nums = new int[n];
    boolean flg = false;
    int current = 0;
    for (int i = 0; i < n; i++) {
      if (flg && "C".equals(line[i])) {
        current++;
        flg = false;
      } else if ("A".equals(line[i])) {
        flg = true;
      } else {
        flg = false;
      }
      nums[i] = current;
    }
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      System.out.println(nums[b] - nums[a]);
    }
  }
}