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