import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

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

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

    } 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 count = 0; count 0 int[] a = new int[n]; a new int[n] n for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        } 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')
                count++;
            a[i] = count;
        } {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        } if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++; 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' count++ count a[i] = count a[i] a i count for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[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(a[r - 1] - a[l - 1]);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[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(a[r - 1] - a[l - 1]) System.out.println System.out System System.out a[r - 1] - a[l - 1] a[r - 1] a r - 1 r 1 a[l - 1] a l - 1 l 1 sc.close() sc.close sc String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

    }
} public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();

        //        boolean ans = false;

        int count = 0;
        int[] a = new int[n];

        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                count++;
            a[i] = count;
        }

        //        if (1200 <= n)
        //            ans = true;

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1] - a[l - 1]);
        }
        sc.close();
        //        System.out.println(ans ? "Yes" : "No");

    }
}