
import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    }
} import java.util.*; util.* java public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    }
} Main static final int 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[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    } main {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    } 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[] str= sc.next().toCharArray(); str sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int ac[] = new int[n]; ac new int[n] n for(int i=0;i<n;i++)ac[i]=0; int i=0; int i=0; i 0 i<n i n i++ i++ i ac[i]=0; ac[i]=0 ac[i] ac i 0 int sum=0; sum 0 for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        } {
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        } if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            } str[i-1]=='A'&&str[i]=='C' str[i-1]=='A' str[i-1] str i-1 i 1 'A' str[i]=='C' str[i] str i 'C' {
                sum++;
            } sum++ sum ac[i]=sum ac[i] ac i sum ac[n-1]=sum ac[n-1] ac n-1 n 1 sum for(int i=0;i<q;i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            System.out.println(ac[r]-ac[l]);
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            System.out.println(ac[r]-ac[l]);
        } {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            System.out.println(ac[r]-ac[l]);
        } int l = sc.nextInt()-1; l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int r = sc.nextInt()-1; r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 System.out.println(ac[r]-ac[l]) System.out.println System.out System System.out ac[r]-ac[l] ac[r] ac r ac[l] ac l String[] args args public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    }
} public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    }
} Main

import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] str= sc.next().toCharArray();
        int ac[] = new int[n];
        for(int i=0;i<n;i++)ac[i]=0;
        int sum=0;

        for(int i=1;i<n;i++){
            if(str[i-1]=='A'&&str[i]=='C'){
                sum++;
            }
            ac[i]=sum;
        }
        ac[n-1]=sum;

        //for(Integer a:ac) System.out.println(a);


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

    }
}
