import java.util.Scanner;

public class Main {

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

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

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

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    } main {
        Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc final int Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc final String S = sc.next(); S sc.next() sc.next sc int[] a = new int[N+1]; a new int[N+1] N+1 N 1 for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[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') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        } {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        } if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[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' {
                a[i+1] = a[i] + 1;
            } a[i+1] = a[i] + 1 a[i+1] a i+1 i 1 a[i] + 1 a[i] a i 1 {
                a[i+1] = a[i];
            } a[i+1] = a[i] a[i+1] a i+1 i 1 a[i] a i for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        } {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        } int l = Integer.valueOf(sc.next()); l Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc int r = Integer.valueOf(sc.next()); r Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc System.out.println(a[--r] - a[--l]) System.out.println System.out System System.out a[--r] - a[--l] a[--r] a --r r a[--l] a --l l String[] args args public class Main {

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

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    }
} public class Main {

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

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    }
} Main
import java.util.Scanner;

public class Main {

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

        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        final String S = sc.next();

        int[] a = new int[N+1];
        for (int i = 0; i  < N; i++) {
            if (i+1 < N && S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                a[i+1] = a[i] + 1;
            } else {
                a[i+1] = a[i];
            }
        }

        for (int i = 0; i < Q; i++) {
            int l = Integer.valueOf(sc.next());
            int r = Integer.valueOf(sc.next());
            System.out.println(a[--r] - a[--l]);
        }
    }
}
