import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

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

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

    } 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[] arr = s.toCharArray(); arr s.toCharArray() s.toCharArray s int[][] lr = new int[q][2]; lr new int[q][2] q 2 for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        } {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        } lr[i][0] = sc.nextInt()-1 lr[i][0] lr[i] lr i 0 sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 lr[i][1] = sc.nextInt()-1 lr[i][1] lr[i] lr i 1 sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int[] flag = new int[n+1]; flag new int[n+1] n+1 n 1 for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        } {
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        } if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            } arr[i]=='A' arr[i] arr i 'A' {
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            } if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                } arr[i+1]=='C' arr[i+1] arr i+1 i 1 'C' {
                    flag[i+1] = 1;
                } flag[i+1] = 1 flag[i+1] flag i+1 i 1 1 int[] cnt = new int[n+2]; cnt new int[n+2] n+2 n 2 for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            cnt[i+1] = cnt[i]+flag[i];
        } {
            cnt[i+1] = cnt[i]+flag[i];
        } cnt[i+1] = cnt[i]+flag[i] cnt[i+1] cnt i+1 i 1 cnt[i]+flag[i] cnt[i] cnt i flag[i] flag i StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        } {
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        } int l = lr[i][0]; l lr[i][0] lr[i] lr i 0 int r = lr[i][1]; r lr[i][1] lr[i] lr i 1 sb.append((cnt[r+1]-cnt[l+1])+"\n") sb.append sb (cnt[r+1]-cnt[l+1])+"\n" (cnt[r+1]-cnt[l+1]) cnt[r+1] cnt r+1 r 1 cnt[l+1] cnt l+1 l 1 "\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 = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

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

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

        System.out.println(sb.toString());

    }
}
