import java.util.Scanner;

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();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
} import java.util.Scanner; Scanner 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();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
} 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();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    } 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 int[] ans = new int[n]; ans new int[n] n for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        } {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        } ans[i] = ans[i - 1] ans[i] ans i ans[i - 1] ans i - 1 i 1 if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            } 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' {
                ans[i]++;
            } ans[i]++ ans[i] ans i StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        } {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        } int l = Integer.parseInt(sc.next()); l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r = Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sb.append(ans[r - 1] - ans[l - 1]) sb.append sb ans[r - 1] - ans[l - 1] ans[r - 1] ans r - 1 r 1 ans[l - 1] ans l - 1 l 1 sb.append("\n") sb.append sb "\n" System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb 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();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
} 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();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
} Main
import java.util.Scanner;

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();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                ans[i]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sb.append(ans[r - 1] - ans[l - 1]);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
}