import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    }
} Main public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    } main {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    } 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 int[] dp = new int[N]; dp new int[N] N dp[0] = 0 dp[0] dp 0 0 for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        } {
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        } if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            } S.charAt(i-1) == 'A' && S.charAt(i) == 'C' S.charAt(i-1) == 'A' S.charAt(i-1) S.charAt S i-1 i 1 'A' S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' {
                dp[i]++;
            } dp[i]++ dp[i] dp i if(i != N-1) dp[i+1] = dp[i]; i != N-1 i N-1 N 1 dp[i+1] = dp[i] dp[i+1] dp i+1 i 1 dp[i] dp i StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        } 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;
            sb.append(dp[r] - dp[l]).append("\r\n");
        } {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        } 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 sb.append(dp[r] - dp[l]).append("\r\n") sb.append(dp[r] - dp[l]).append sb.append(dp[r] - dp[l]) sb.append sb dp[r] - dp[l] dp[r] dp r dp[l] dp l "\r\n" System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    }
}
