import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc int[] l = new int[Q] l new int[Q] Q r = new int[Q]; r new int[Q] Q for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc char[] letter = S.toCharArray(); letter S.toCharArray() S.toCharArray S int[] ac = new int[N+1]; ac new int[N+1] N+1 N 1 ac[0] = 0 ac[0] ac 0 0 for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        } {
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        } ac[i] = ac[i-1] ac[i] ac i ac[i-1] ac i-1 i 1 if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            } letter[i-1] == 'A' letter[i-1] letter i-1 i 1 'A' {
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            } if(letter[i] == 'C'){
                    ac[i]++;
                } letter[i] == 'C' letter[i] letter i 'C' {
                    ac[i]++;
                } ac[i]++ ac[i] ac i for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        } {
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        } System.out.println(ac[r[i]-1] - ac[l[i]-1]) System.out.println System.out System System.out ac[r[i]-1] - ac[l[i]-1] ac[r[i]-1] ac r[i]-1 r[i] r i 1 ac[l[i]-1] ac l[i]-1 l[i] l i 1 String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),
            Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q],
              r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        char[] letter = S.toCharArray();
        int[] ac = new int[N+1];
        ac[0] = 0;
        for(int i = 1; i < N; i++){
            ac[i] = ac[i-1];
            if(letter[i-1] == 'A'){
                if(letter[i] == 'C'){
                    ac[i]++;
                }
            }
        }
        for(int i = 0; i < Q; i++){
            System.out.println(ac[r[i]-1] - ac[l[i]-1]);
        }        
    }
}