
import java.util.Scanner;

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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    }
    
} import java.util.Scanner; Scanner 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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    }
    
} 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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    } 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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    } 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[] sum = new int[n+1]; sum new int[n+1] n+1 n 1 for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        } {
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        } if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            } s[i] == 'C' && s[i-1] == 'A' s[i] == 'C' s[i] s i 'C' s[i-1] == 'A' s[i-1] s i-1 i 1 'A' {
                sum[i+1] = sum[i] + 1;
            } sum[i+1] = sum[i] + 1 sum[i+1] sum i+1 i 1 sum[i] + 1 sum[i] sum i 1 {
                sum[i+1] = sum[i];
            } sum[i+1] = sum[i] sum[i+1] sum i+1 i 1 sum[i] sum i int l l r; r StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        } {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        } l = Integer.parseInt(sc.next()) l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sb.append(sum[r]-sum[l]) sb.append sb sum[r]-sum[l] sum[r] sum r sum[l] sum l sb.append('\n') sb.append sb '\n' System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb sc.close() sc.close sc 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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    }
    
} 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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    }
    
} Main

import java.util.Scanner;

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[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    }
    
}