import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        }
        
        
        
        
        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        }
        
        
        
        
        
    }
} Main public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        }
        
        
        
        
        
    } main {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[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 String S=sc.next(); S sc.next() sc.next sc char[] s=S.toCharArray(); s S.toCharArray() S.toCharArray S int [] num=new int[N]; num new int[N] N int count=0; count 0 for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        } int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        } {
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        } if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            } s[i]=='A'&&s[i+1]=='C' s[i]=='A' s[i] s i 'A' s[i+1]=='C' s[i+1] s i+1 i 1 'C' {
                count++;    
            } count++ count num[i+1]=count num[i+1] num i+1 i 1 count int l=0; l 0 int r=0; r 0 for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        } {
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        } l=sc.nextInt()-1 l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 r=sc.nextInt()-1 r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 System.out.println(num[r]-num[l]) System.out.println System.out System System.out num[r]-num[l] num[r] num r num[l] num l String args[] args public class Main {
    public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        }
        
        
        
        
        
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        }
        
        
        
        
        
    }
} Main
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        int N= sc.nextInt();
        int Q= sc.nextInt();

        String S=sc.next();
        char[] s=S.toCharArray();
        int [] num=new int[N];
        int count=0;
        for(int i=0;i<N-1;i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                count++;    
            }
            num[i+1]=count;
            
        }
        int l=0;
        int r=0;
        for(int i=0;i<Q;i++){
            l=sc.nextInt()-1;
            r=sc.nextInt()-1;
            System.out.println(num[r]-num[l]);
        }
        
        
        
        
        
    }
}
