import java.util.*;

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    }
} Main public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    } 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 sc.nextLine() sc.nextLine sc String s = sc.nextLine(); s sc.nextLine() sc.nextLine sc int[] arr = new int[n]; arr new int[n] n for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        } {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        } if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[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' arr[i]++ arr[i] arr i arr[i] += arr[i-1] arr[i] arr i arr[i-1] arr i-1 i 1 for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        } {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        } int start = sc.nextInt() - 1; start sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int end = sc.nextInt() - 1; end sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 System.out.println(arr[end] - arr[start]) System.out.println System.out System System.out arr[end] - arr[start] arr[end] arr end arr[start] arr start String args[] args public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    }
} public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    }
}