import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[][] range = new int[q][2];
        for(int i = 0; i < q; i++){
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        }
        int[] frag = new int[n + 1];
        int[] rui = new int[n + 1];
        for(int i = 2; i <= n; i++){
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        }
        for(int i = 0; i < q; i++){
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        }
    }
} import java.util.*; util.* java class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[][] range = new int[q][2];
        for(int i = 0; i < q; i++){
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        }
        int[] frag = new int[n + 1];
        int[] rui = new int[n + 1];
        for(int i = 2; i <= n; i++){
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        }
        for(int i = 0; i < q; i++){
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        }
    }
} Main final static long mod = 1000000007; mod 1000000007 //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[][] range = new int[q][2];
        for(int i = 0; i < q; i++){
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        }
        int[] frag = new int[n + 1];
        int[] rui = new int[n + 1];
        for(int i = 2; i <= n; i++){
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        }
        for(int i = 0; i < q; i++){
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[][] range = new int[q][2];
        for(int i = 0; i < q; i++){
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        }
        int[] frag = new int[n + 1];
        int[] rui = new int[n + 1];
        for(int i = 2; i <= n; i++){
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        }
        for(int i = 0; i < q; i++){
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        }
    } 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 char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[][] range = new int[q][2]; range new int[q][2] q 2 for(int i = 0; i < q; i++){
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        } {
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        } range[i][0] = sc.nextInt() range[i][0] range[i] range i 0 sc.nextInt() sc.nextInt sc range[i][1] = sc.nextInt() range[i][1] range[i] range i 1 sc.nextInt() sc.nextInt sc int[] frag = new int[n + 1]; frag new int[n + 1] n + 1 n 1 int[] rui = new int[n + 1]; rui new int[n + 1] n + 1 n 1 for(int i = 2; i <= n; i++){
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        } int i = 2; int i = 2; i 2 i <= n i n i++ i++ i {
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        } {
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        } if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            } c[i - 2] == 'A' && c[i - 1] == 'C' c[i - 2] == 'A' c[i - 2] c i - 2 i 2 'A' c[i - 1] == 'C' c[i - 1] c i - 1 i 1 'C' {
                frag[i]++;
            } frag[i]++ frag[i] frag i rui[i] = rui[i - 1] + frag[i] rui[i] rui i rui[i - 1] + frag[i] rui[i - 1] rui i - 1 i 1 frag[i] frag i for(int i = 0; i < q; i++){
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        } {
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        } int left = range[i][0]; left range[i][0] range[i] range i 0 int right = range[i][1]; right range[i][1] range[i] range i 1 System.out.println(rui[right] - rui[left]) System.out.println System.out System System.out rui[right] - rui[left] rui[right] rui right rui[left] rui left String[] args args
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[][] range = new int[q][2];
        for(int i = 0; i < q; i++){
            range[i][0] = sc.nextInt();
            range[i][1] = sc.nextInt();
        }
        int[] frag = new int[n + 1];
        int[] rui = new int[n + 1];
        for(int i = 2; i <= n; i++){
            if(c[i - 2] == 'A' && c[i - 1] == 'C'){
                frag[i]++;
            }
            rui[i] = rui[i - 1] + frag[i];
        }
        for(int i = 0; i < q; i++){
            int left = range[i][0];
            int right = range[i][1];
            System.out.println(rui[right] - rui[left]);
        }
    }
}