import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    }
} import java.util.*; util.* java public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc char[] s = sc.next().toCharArray(); s sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] a = new int[n]; a new int[n] n for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        } 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'){
                a[i+1] = 1;
            }
        } {
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        } if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            } 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' {
                a[i+1] = 1;
            } a[i+1] = 1 a[i+1] a i+1 i 1 1 for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            a[i+1] += a[i];
        } {
            a[i+1] += a[i];
        } a[i+1] += a[i] a[i+1] a i+1 i 1 a[i] a i for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        } {
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        } int l = Integer.parseInt(sc.next())-1; l Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 int r = Integer.parseInt(sc.next())-1; r Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 System.out.println(a[r]-a[l]) System.out.println System.out System System.out a[r]-a[l] a[r] a r a[l] a l String[] args args public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    }
} public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    }
} Main
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    }
}
