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();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        }
    }
} 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();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[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 String ss = sc.next(); ss sc.next() sc.next sc char[] s = ss.toCharArray(); s ss.toCharArray() ss.toCharArray ss int[] ac = new int[n+1]; ac new int[n+1] n+1 n 1 ArrayList<Integer> acl = new ArrayList<>(); acl new ArrayList<>() int i = 1; i 1 boolean prevA = false; prevA false for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        } char c s {
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        } {
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        } if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            } c == 'A' c 'A' {
                prevA = true;
            } prevA = true prevA true if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            } c == 'C' && prevA c == 'C' c 'C' prevA {
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            } ac[i-1]++ ac[i-1] ac i-1 i 1 prevA = false prevA false {
                prevA = false;
            } prevA = false prevA false i++ i for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        } int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        } {
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        } ac[j] += ac[j-1] ac[j] ac j ac[j-1] ac j-1 j 1 for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        } int j = 0; int j = 0; j 0 j < q j q j++ j++ j {
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        } {
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        } int left = sc.nextInt()-1; left sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int right = sc.nextInt()-1; right sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 System.out.println(ac[right] - ac[left]) System.out.println System.out System System.out ac[right] - ac[left] ac[right] ac right ac[left] ac left 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();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        }
    }
} 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();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        }
    }
} 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();
        String ss = sc.next();
        char[] s = ss.toCharArray();
        int[] ac = new int[n+1];
        ArrayList<Integer> acl = new ArrayList<>();
        int i = 1;
        boolean prevA = false;
        for(char c : s){
            if(c == 'A'){
                prevA = true;
            }else if(c == 'C' && prevA){
                //System.out.println(i-1);
                ac[i-1]++;
                prevA = false;
            }else{
                prevA = false;
            }
            i++;
        }
        //System.out.print(ac[0] + " ");
        for(int j = 1; j <= n; j++){
            ac[j] += ac[j-1];
            //System.out.print(ac[j] + " ");
        }
        //System.out.println();
        for(int j = 0; j < q; j++){
            int left = sc.nextInt()-1;
            int right = sc.nextInt()-1;
            System.out.println(ac[right] - ac[left]);
        }
    }
}