import 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];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

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

} import java.util.*; util.* java 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];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

        for (int i=0;i<q;i++){
            System.out.println(integer[r[i]-1]-integer[l[i]-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();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

        for (int i=0;i<q;i++){
            System.out.println(integer[r[i]-1]-integer[l[i]-1]);
        }
    } 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];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

        for (int i=0;i<q;i++){
            System.out.println(integer[r[i]-1]-integer[l[i]-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 int[] l = new int[q]; l new int[q] q int[] r = new int[q]; r new int[q] q 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[] integer = new int[n]; integer new int[n] n integer[0] = 0 integer[0] integer 0 0 for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        } {
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        } if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            } s.charAt(i)=='A'&&s.charAt(i+1)=='C' s.charAt(i)=='A' s.charAt(i) s.charAt s i 'A' s.charAt(i+1)=='C' s.charAt(i+1) s.charAt s i+1 i 1 'C' {
                integer[i+1]=integer[i]+1;
            } integer[i+1]=integer[i]+1 integer[i+1] integer i+1 i 1 integer[i]+1 integer[i] integer i 1 {
                integer[i+1]=integer[i];
            } integer[i+1]=integer[i] integer[i+1] integer i+1 i 1 integer[i] integer i for (int i=0;i<q;i++){
            System.out.println(integer[r[i]-1]-integer[l[i]-1]);
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            System.out.println(integer[r[i]-1]-integer[l[i]-1]);
        } {
            System.out.println(integer[r[i]-1]-integer[l[i]-1]);
        } System.out.println(integer[r[i]-1]-integer[l[i]-1]) System.out.println System.out System System.out integer[r[i]-1]-integer[l[i]-1] integer[r[i]-1] integer r[i]-1 r[i] r i 1 integer[l[i]-1] integer l[i]-1 l[i] l i 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();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

        for (int i=0;i<q;i++){
            System.out.println(integer[r[i]-1]-integer[l[i]-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();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

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

} Main
import 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];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

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

}