
import java.util.Scanner;

public class Main {

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    }

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

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    }

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int Q = scanner.nextInt(); Q scanner.nextInt() scanner.nextInt scanner String S = scanner.next(); S scanner.next() scanner.next scanner boolean flag = false; flag false char[] charArray = S.toCharArray(); charArray S.toCharArray() S.toCharArray S int count = 0; count 0 int[] ret = new int[N]; ret new int[N] N for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        } int i = N-1; int i = N-1; i N-1 N 1 i >= 0 i 0 i-- i-- i {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        } {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        } char c = charArray[i]; c charArray[i] charArray i if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            } c == 'C' c 'C' {
                flag = true;
            } flag = true flag true if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            } c == 'A' c 'A' {
                if (flag) {
                    count++;
                }
                flag = false;
            } if (flag) {
                    count++;
                } flag {
                    count++;
                } count++ count flag = false flag false {
                flag = false;
            } flag = false flag false ret[i] = count ret[i] ret i count for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        } {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        } int l = scanner.nextInt(); l scanner.nextInt() scanner.nextInt scanner int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner System.out.println(ret[l-1]-ret[r-1]) System.out.println System.out System System.out ret[l-1]-ret[r-1] ret[l-1] ret l-1 l 1 ret[r-1] ret r-1 r 1 String[] args args public class Main {

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    }

} public class Main {

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    }

} Main

import java.util.Scanner;

public class Main {

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        boolean flag = false;
        char[] charArray = S.toCharArray();
        int count = 0;
        int[] ret = new int[N];
        for (int i = N-1; i >= 0; i--) {
            char c = charArray[i];
            if (c == 'C') {
                flag = true;
            } else if (c == 'A') {
                if (flag) {
                    count++;
                }
                flag = false;
            } else {
                flag = false;
            }
            ret[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();

            System.out.println(ret[l-1]-ret[r-1]);
        }
    }

}
