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 s = sc.next();

        int[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

        for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        }
    }
} 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 s = sc.next();

        int[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

        for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        }
    }
} 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[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

        for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        int[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

        for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        }
    } 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[] arr = new int[n + 1]; arr new int[n + 1] n + 1 n 1 Arrays.fill(arr, 0) Arrays.fill Arrays arr 0 for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        } {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        } if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i]; i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C' i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C' i + 1 < n i + 1 i 1 n 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' arr[i + 1] = arr[i] + 1 arr[i + 1] arr i + 1 i 1 arr[i] + 1 arr[i] arr i 1 arr[i + 1] = arr[i] arr[i + 1] arr i + 1 i 1 arr[i] arr i for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        } int i = 0; int i = 0; i 0 i < q i q ++i ++i i {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        } {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        } int l = sc.nextInt() - 1; l sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int r = sc.nextInt() - 1; r sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 System.out.println(arr[r] - arr[l]) System.out.println System.out System System.out arr[r] - arr[l] arr[r] arr r arr[l] arr l 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 s = sc.next();

        int[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

        for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        }
    }
} public 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[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

        for (int i = 0; i < q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(arr[r] - arr[l]);
        }
    }
} 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 s = sc.next();

        int[] arr = new int[n + 1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < n; ++i) {
            if (i + 1 < n && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                arr[i + 1] = arr[i] + 1;
            else
                arr[i + 1] = arr[i];
        }

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