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();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    }
} 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();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    }
} 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();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    } 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 int l[] = new int[Q]; l new int[Q] Q int r[] = new int[Q]; r new int[Q] Q char a[] = new char[N]; a new char[N] N int count[] = new int[N]; count new int[N] N for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = S.charAt(i);
        } {
            a[i] = S.charAt(i);
        } a[i] = S.charAt(i) a[i] a i S.charAt(i) S.charAt S i for (int i = 0; i < Q; i++) {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        } {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        } l[i] = scanner.nextInt() l[i] l i scanner.nextInt() scanner.nextInt scanner r[i] = scanner.nextInt() r[i] r i scanner.nextInt() scanner.nextInt scanner int sum[] = new int[N]; sum new int[N] N for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        } {
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        } if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            } a[i] == 'A' && a[i + 1] == 'C' a[i] == 'A' a[i] a i 'A' a[i + 1] == 'C' a[i + 1] a i + 1 i 1 'C' {
                count[i + 1] += 1;
            } count[i + 1] += 1 count[i + 1] count i + 1 i 1 1 for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            sum[i] += count[i] + sum[i - 1];
        } {
            sum[i] += count[i] + sum[i - 1];
        } sum[i] += count[i] + sum[i - 1] sum[i] sum i count[i] + sum[i - 1] count[i] count i sum[i - 1] sum i - 1 i 1 for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        } {
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        } int total = sum[r[i] - 1] - sum[l[i] - 1]; total sum[r[i] - 1] - sum[l[i] - 1] sum[r[i] - 1] sum r[i] - 1 r[i] r i 1 sum[l[i] - 1] sum l[i] - 1 l[i] l i 1 System.out.println(total) System.out.println System.out System System.out total 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();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    }
} 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();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    }
} 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();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

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

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    }
}