import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner 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();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	}
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	} main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	} 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 ArrayList<Integer> List = new ArrayList<Integer>(); List new ArrayList<Integer>() int num=0; num 0 for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        } int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        } {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        } char s = S.charAt(i); s S.charAt(i) S.charAt S i char s2 = S.charAt(i+1); s2 S.charAt(i+1) S.charAt S i+1 i 1 if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num); s=='A'&&s2=='C' s=='A' s 'A' s2=='C' s2 'C' {
                List.add(num);
                num+=1;
            } List.add(num) List.add List num num+=1 num 1 List.add(num) List.add List num List.add(num) List.add List num for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int opt =List.get(r-1)-List.get(l-1); opt List.get(r-1)-List.get(l-1) List.get(r-1) List.get List r-1 r 1 List.get(l-1) List.get List l-1 l 1 System.out.println(opt) System.out.println System.out System System.out opt 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();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	}
} public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        ArrayList<Integer> List = new ArrayList<Integer>();
        int num=0;
        for(int i=0;i<N-1;i++) {
            char s = S.charAt(i);
            char s2 = S.charAt(i+1);
            if(s=='A'&&s2=='C'){
                List.add(num);
                num+=1;
            }
            else List.add(num);
        }
        List.add(num);
        for(int i=0;i<Q;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int opt =List.get(r-1)-List.get(l-1);
            System.out.println(opt);
        }
	}
}
