import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] NQ = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        }
        String S = br.readLine();
        String[] s = S.split("");
        int[] cumulative_sum = new int[NQ[0]+1];
        cont = 0;
        for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        }
        int[] lr = new int[2];
        for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        }
    }
} import java.io.*; io.* java class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] NQ = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        }
        String S = br.readLine();
        String[] s = S.split("");
        int[] cumulative_sum = new int[NQ[0]+1];
        cont = 0;
        for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        }
        int[] lr = new int[2];
        for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        }
    }
} Main public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] NQ = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        }
        String S = br.readLine();
        String[] s = S.split("");
        int[] cumulative_sum = new int[NQ[0]+1];
        cont = 0;
        for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        }
        int[] lr = new int[2];
        for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] NQ = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        }
        String S = br.readLine();
        String[] s = S.split("");
        int[] cumulative_sum = new int[NQ[0]+1];
        cont = 0;
        for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        }
        int[] lr = new int[2];
        for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str = br.readLine(); str br.readLine() br.readLine br int[] NQ = new int[2]; NQ new int[2] 2 int cont = 0; cont 0 for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        } String s str.split(" ") str.split str " " {
            NQ[cont] = Integer.parseInt(s);
            cont++;
        } {
            NQ[cont] = Integer.parseInt(s);
            cont++;
        } NQ[cont] = Integer.parseInt(s) NQ[cont] NQ cont Integer.parseInt(s) Integer.parseInt Integer s cont++ cont String S = br.readLine(); S br.readLine() br.readLine br String[] s = S.split(""); s S.split("") S.split S "" int[] cumulative_sum = new int[NQ[0]+1]; cumulative_sum new int[NQ[0]+1] NQ[0]+1 NQ[0] NQ 0 1 cont = 0 cont 0 for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        } int i=1; int i=1; i 1 i<NQ[0] i NQ[0] NQ 0 i++ i++ i {
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        } {
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        } if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            } s[i].equals("C") && s[i-1].equals("A") s[i].equals("C") s[i].equals s[i] s i "C" s[i-1].equals("A") s[i-1].equals s[i-1] s i-1 i 1 "A" {
                cont += 1;
            } cont += 1 cont 1 cumulative_sum[i+1] = cont cumulative_sum[i+1] cumulative_sum i+1 i 1 cont int[] lr = new int[2]; lr new int[2] 2 for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        } int i=0; int i=0; i 0 i<NQ[1] i NQ[1] NQ 1 i++ i++ i {
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        } {
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        } str = br.readLine() str br.readLine() br.readLine br cont = 0 cont 0 for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            } String t str.split(" ") str.split str " " {
                lr[cont] = Integer.parseInt(t);
                cont++;
            } {
                lr[cont] = Integer.parseInt(t);
                cont++;
            } lr[cont] = Integer.parseInt(t) lr[cont] lr cont Integer.parseInt(t) Integer.parseInt Integer t cont++ cont System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]) System.out.println System.out System System.out cumulative_sum[lr[1]]-cumulative_sum[lr[0]] cumulative_sum[lr[1]] cumulative_sum lr[1] lr 1 cumulative_sum[lr[0]] cumulative_sum lr[0] lr 0 String[] args args
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] NQ = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        }
        String S = br.readLine();
        String[] s = S.split("");
        int[] cumulative_sum = new int[NQ[0]+1];
        cont = 0;
        for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        }
        int[] lr = new int[2];
        for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        }
    }
}