import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        int quesNum = sc.nextInt();
        String input = sc.next();

        Dp dp = new Dp(len, input);
        
        for(int i = 0; i < quesNum; i++){
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        }
    }
}

class Dp {
    static int[] dp;
    String input;
    public Dp (int num, String input) {
        dp = new int[num+1];
        for(int i = 0; i <= num; i++) {
            dp[i] = -1;  
        }
        this.input = input;
    }

    public int part(int right) {
        if(dp[right] != -1)return dp[right];
        
        if(right <= 1) {
            dp[right] = 0;
            return dp[right];
        }
        
        int ans = 0;
        if(input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C') {
            ans = part(right-2) + 1;
        }
        else ans = part(right-1);

        dp[right] = ans;
        return dp[right];
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        int quesNum = sc.nextInt();
        String input = sc.next();

        Dp dp = new Dp(len, input);
        
        for(int i = 0; i < quesNum; i++){
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        int quesNum = sc.nextInt();
        String input = sc.next();

        Dp dp = new Dp(len, input);
        
        for(int i = 0; i < quesNum; i++){
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        int quesNum = sc.nextInt();
        String input = sc.next();

        Dp dp = new Dp(len, input);
        
        for(int i = 0; i < quesNum; i++){
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int len = sc.nextInt(); len sc.nextInt() sc.nextInt sc int quesNum = sc.nextInt(); quesNum sc.nextInt() sc.nextInt sc String input = sc.next(); input sc.next() sc.next sc Dp dp = new Dp(len, input); dp new Dp(len, input) for(int i = 0; i < quesNum; i++){
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        } int i = 0; int i = 0; i 0 i < quesNum i quesNum i++ i++ i {
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        } {
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        } int ans = 0; ans 0 int left = sc.nextInt(); left sc.nextInt() sc.nextInt sc int right = sc.nextInt(); right sc.nextInt() sc.nextInt sc ans = dp.part(right) - dp.part(left) ans dp.part(right) - dp.part(left) dp.part(right) dp.part dp right dp.part(left) dp.part dp left System.out.println(ans) System.out.println System.out System System.out ans String[] args args class Dp {
    static int[] dp;
    String input;
    public Dp (int num, String input) {
        dp = new int[num+1];
        for(int i = 0; i <= num; i++) {
            dp[i] = -1;  
        }
        this.input = input;
    }

    public int part(int right) {
        if(dp[right] != -1)return dp[right];
        
        if(right <= 1) {
            dp[right] = 0;
            return dp[right];
        }
        
        int ans = 0;
        if(input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C') {
            ans = part(right-2) + 1;
        }
        else ans = part(right-1);

        dp[right] = ans;
        return dp[right];
    }
} Dp static int[] dp; dp String input; input public Dp (int num, String input) {
        dp = new int[num+1];
        for(int i = 0; i <= num; i++) {
            dp[i] = -1;  
        }
        this.input = input;
    } Dp {
        dp = new int[num+1];
        for(int i = 0; i <= num; i++) {
            dp[i] = -1;  
        }
        this.input = input;
    } dp = new int[num+1] dp new int[num+1] num+1 num 1 for(int i = 0; i <= num; i++) {
            dp[i] = -1;  
        } int i = 0; int i = 0; i 0 i <= num i num i++ i++ i {
            dp[i] = -1;  
        } {
            dp[i] = -1;  
        } dp[i] = -1 dp[i] dp i -1 1 this.input = input this.input this this.input input int num num String input input public int part(int right) {
        if(dp[right] != -1)return dp[right];
        
        if(right <= 1) {
            dp[right] = 0;
            return dp[right];
        }
        
        int ans = 0;
        if(input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C') {
            ans = part(right-2) + 1;
        }
        else ans = part(right-1);

        dp[right] = ans;
        return dp[right];
    } part {
        if(dp[right] != -1)return dp[right];
        
        if(right <= 1) {
            dp[right] = 0;
            return dp[right];
        }
        
        int ans = 0;
        if(input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C') {
            ans = part(right-2) + 1;
        }
        else ans = part(right-1);

        dp[right] = ans;
        return dp[right];
    } if(dp[right] != -1)return dp[right]; dp[right] != -1 dp[right] dp right -1 1 return dp[right]; dp[right] dp right if(right <= 1) {
            dp[right] = 0;
            return dp[right];
        } right <= 1 right 1 {
            dp[right] = 0;
            return dp[right];
        } dp[right] = 0 dp[right] dp right 0 return dp[right]; dp[right] dp right int ans = 0; ans 0 if(input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C') {
            ans = part(right-2) + 1;
        }
        else ans = part(right-1); input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C' input.charAt(right-2) == 'A' input.charAt(right-2) input.charAt input right-2 right 2 'A' input.charAt(right-1) == 'C' input.charAt(right-1) input.charAt input right-1 right 1 'C' {
            ans = part(right-2) + 1;
        } ans = part(right-2) + 1 ans part(right-2) + 1 part(right-2) part right-2 right 2 1 ans = part(right-1) ans part(right-1) part right-1 right 1 dp[right] = ans dp[right] dp right ans return dp[right]; dp[right] dp right int right right
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        int quesNum = sc.nextInt();
        String input = sc.next();

        Dp dp = new Dp(len, input);
        
        for(int i = 0; i < quesNum; i++){
            int ans = 0;
            int left = sc.nextInt();
            int right = sc.nextInt();
          
            ans = dp.part(right) - dp.part(left);
            System.out.println(ans);
        }
    }
}

class Dp {
    static int[] dp;
    String input;
    public Dp (int num, String input) {
        dp = new int[num+1];
        for(int i = 0; i <= num; i++) {
            dp[i] = -1;  
        }
        this.input = input;
    }

    public int part(int right) {
        if(dp[right] != -1)return dp[right];
        
        if(right <= 1) {
            dp[right] = 0;
            return dp[right];
        }
        
        int ans = 0;
        if(input.charAt(right-2) == 'A' && input.charAt(right-1) == 'C') {
            ans = part(right-2) + 1;
        }
        else ans = part(right-1);

        dp[right] = ans;
        return dp[right];
    }
}