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 s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    }
} 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 s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    }
} 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 s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    } main {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    } 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 s = sc.next(); s sc.next() sc.next sc Integer[] l = new Integer[q]; l new Integer[q] q Integer[] r = new Integer[q]; r new Integer[q] q for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int[] arr = new int[n]; arr new int[n] n for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        } {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        } if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            } s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' {
                arr[i] = arr[i - 1] + 1;
            } arr[i] = arr[i - 1] + 1 arr[i] arr i arr[i - 1] + 1 arr[i - 1] arr i - 1 i 1 1 {
                arr[i] = arr[i - 1];
            } arr[i] = arr[i - 1] arr[i] arr i arr[i - 1] arr i - 1 i 1 for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        } {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        } int result = arr[r[i] - 1] - arr[l[i] - 1]; result arr[r[i] - 1] - arr[l[i] - 1] arr[r[i] - 1] arr r[i] - 1 r[i] r i 1 arr[l[i] - 1] arr l[i] - 1 l[i] l i 1 System.out.println(result) System.out.println System.out System System.out result 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 s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    }
} 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 s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    }
} 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 s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i] = arr[i - 1] + 1;
            } else {
                arr[i] = arr[i - 1];
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    }
}
