import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

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

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

} Main private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    } solve {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    } 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 char[] SCharArray = S.toCharArray(); SCharArray S.toCharArray() S.toCharArray S int[] left = new int[Q]; left new int[Q] Q int[] right = new int[Q]; right new int[Q] Q for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        } {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        } left[i] = sc.nextInt() left[i] left i sc.nextInt() sc.nextInt sc right[i] = sc.nextInt() right[i] right i sc.nextInt() sc.nextInt sc int[] accumCounts = new int[N]; accumCounts new int[N] N for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        } {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        } if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            } SCharArray[i] == 'A' && SCharArray[i + 1] == 'C' SCharArray[i] == 'A' SCharArray[i] SCharArray i 'A' SCharArray[i + 1] == 'C' SCharArray[i + 1] SCharArray i + 1 i 1 'C' {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            } accumCounts[i + 1] = (accumCounts[i] + 1) accumCounts[i + 1] accumCounts i + 1 i 1 (accumCounts[i] + 1) accumCounts[i] accumCounts i 1 {
                accumCounts[i + 1] = accumCounts[i];
            } accumCounts[i + 1] = accumCounts[i] accumCounts[i + 1] accumCounts i + 1 i 1 accumCounts[i] accumCounts i for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        } {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        } System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]) System.out.println System.out System System.out accumCounts[right[i] - 1] - accumCounts[left[i] - 1] accumCounts[right[i] - 1] accumCounts right[i] - 1 right[i] right i 1 accumCounts[left[i] - 1] accumCounts left[i] - 1 left[i] left i 1 // Main
    public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

} public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        char[] SCharArray = S.toCharArray();
        int[] left = new int[Q];
        int[] right = new int[Q];
        for (int i = 0; i < Q; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int[] accumCounts = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (SCharArray[i] == 'A' && SCharArray[i + 1] == 'C') {
                accumCounts[i + 1] = (accumCounts[i] + 1);
            }
            else {
                accumCounts[i + 1] = accumCounts[i];
            }
        }
        //accumCounts[N - 1] = accumCounts[N - 2];

        //for (int i = 0; i < N; i++) {
        //   System.out.println(accumCounts[i]);
        //}
        for (int i = 0; i < Q; i++) {
            System.out.println(accumCounts[right[i] - 1] - accumCounts[left[i] - 1]);
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

}
