/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        abc122cGeTACsolve();
    }

    public static void abc122cGeTACsolve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        int[] ruiseki = new int[n];
        int ans = 0;
        for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        }
        for (int i = 0; i < q; i++) {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        }
    }
}


 import java.util.*; util.* java import java.lang.*; lang.* java import java.math.*; math.* java class Main{
    public static void main(String[] args){
        abc122cGeTACsolve();
    }

    public static void abc122cGeTACsolve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        int[] ruiseki = new int[n];
        int ans = 0;
        for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        }
        for (int i = 0; i < q; i++) {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        }
    }
} Main public static void main(String[] args){
        abc122cGeTACsolve();
    } main {
        abc122cGeTACsolve();
    } abc122cGeTACsolve() abc122cGeTACsolve String[] args args public static void abc122cGeTACsolve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        int[] ruiseki = new int[n];
        int ans = 0;
        for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        }
        for (int i = 0; i < q; i++) {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        }
    } abc122cGeTACsolve {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        int[] ruiseki = new int[n];
        int ans = 0;
        for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        }
        for (int i = 0; i < q; i++) {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        }
    } 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 int[] l = new int[q]; l new int[q] q int[] r = new int[q]; r new int[q] q int[] ruiseki = new int[n]; ruiseki new int[n] n int ans = 0; ans 0 for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        } {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc l[i]-- l[i] l i r[i]-- r[i] r i for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        } 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'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        } {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        } if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            } 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' {
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            } if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                } i == 0 i 0 {
                    ruiseki[i] = 1;
                } ruiseki[i] = 1 ruiseki[i] ruiseki i 1 {
                    ruiseki[i] = ruiseki[i-1] + 1;
                } ruiseki[i] = ruiseki[i-1] + 1 ruiseki[i] ruiseki i ruiseki[i-1] + 1 ruiseki[i-1] ruiseki i-1 i 1 1 {
                ruiseki[i] = ruiseki[i-1];
            } ruiseki[i] = ruiseki[i-1] ruiseki[i] ruiseki i ruiseki[i-1] ruiseki i-1 i 1 for (int i = 0; i < q; i++) {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        } {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        } System.out.println(ruiseki[r[i]] - ruiseki[l[i]]) System.out.println System.out System System.out ruiseki[r[i]] - ruiseki[l[i]] ruiseki[r[i]] ruiseki r[i] r i ruiseki[l[i]] ruiseki l[i] l i
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        abc122cGeTACsolve();
    }

    public static void abc122cGeTACsolve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        int[] ruiseki = new int[n];
        int ans = 0;
        for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            l[i]--;
            r[i]--;
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
                if(i == 0){
                    ruiseki[i] = 1;
                }else{
                    ruiseki[i] = ruiseki[i-1] + 1;
                }
            }else{
                ruiseki[i] = ruiseki[i-1];
            }
        }
        for (int i = 0; i < q; i++) {
            System.out.println(ruiseki[r[i]] - ruiseki[l[i]]);  
        }
    }
}



