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();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    }
} 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();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    } 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 char[] arr = sc.next().toCharArray(); arr sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] countArr = new int[n]; countArr new int[n] n int count = 0; count 0 countArr[0] = 0 countArr[0] countArr 0 0 for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        } int i = 1; int i = 1; i 1 i < arr.length i arr.length arr arr.length i++ i++ i {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        } {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        } if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            } "AC".equals("" + arr[i - 1] + arr[i]) "AC".equals "AC" "" + arr[i - 1] + arr[i] "" + arr[i - 1] + arr[i] "" arr[i - 1] arr i - 1 i 1 arr[i] arr i {
                count++;
            } count++ count countArr[i] = count countArr[i] countArr i count for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(countArr[r - 1] - countArr[l - 1]) System.out.println System.out System System.out countArr[r - 1] - countArr[l - 1] countArr[r - 1] countArr r - 1 r 1 countArr[l - 1] countArr l - 1 l 1 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();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    }
} 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();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    }
}
