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();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  }
} 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();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
        int q = sc.nextInt();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  } main {
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
        int q = sc.nextInt();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  } 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 int [] L = new int [n]; L new int [n] n int [] R = new int [n]; R new int [n] n String s = sc.next(); s sc.next() sc.next sc int count = 0; count 0 L[0]=0 L[0] L 0 0 R[n-1]=0 R[n-1] R n-1 n 1 0 for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {if(s.substring(i,i+2).equals("AC")){count++;}
                            } {if(s.substring(i,i+2).equals("AC")){count++;}
                            } if(s.substring(i,i+2).equals("AC")){count++;} s.substring(i,i+2).equals("AC") s.substring(i,i+2).equals s.substring(i,i+2) s.substring s i i+2 i 2 "AC" {count++;} count++ count for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            } int i=1; int i=1; i 1 i<n i n i++ i++ i {if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            } {if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            } if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];} s.substring(i-1,i+1).equals("AC") s.substring(i-1,i+1).equals s.substring(i-1,i+1) s.substring s i-1 i 1 i+1 i 1 "AC" {L[i]=L[i-1]+1;} L[i]=L[i-1]+1 L[i] L i L[i-1]+1 L[i-1] L i-1 i 1 1 {L[i]=L[i-1];} L[i]=L[i-1] L[i] L i L[i-1] L i-1 i 1 for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            } int i=n-2; int i=n-2; i n-2 n 2 i>=0 i 0 i-- i-- i {if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            } {if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            } if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];} s.substring(i,i+2).equals("AC") s.substring(i,i+2).equals s.substring(i,i+2) s.substring s i i+2 i 2 "AC" {R[i]=R[i+1]+1;} R[i]=R[i+1]+1 R[i] R i R[i+1]+1 R[i+1] R i+1 i 1 1 {R[i]=R[i+1];} R[i]=R[i+1] R[i] R i R[i+1] R i+1 i 1 for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);} int i=0; int i=0; i 0 i<q i q i++ i++ i {int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);} {int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(L[r-1]+R[l-1]-count) System.out.println System.out System System.out L[r-1]+R[l-1]-count L[r-1]+R[l-1] L[r-1] L r-1 r 1 R[l-1] R l-1 l 1 count 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();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  }
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
        int q = sc.nextInt();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  }
} 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();
		int [] L = new int [n];
        int [] R = new int [n];
        String s = sc.next();
        int count = 0;
        L[0]=0;
        R[n-1]=0;
        for(int i=0;i<n-1;i++){if(s.substring(i,i+2).equals("AC")){count++;}
                            }	
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }
        for(int i=n-2;i>=0;i--){if(s.substring(i,i+2).equals("AC")){R[i]=R[i+1]+1;}
                                else{R[i]=R[i+1];}
                            }                       
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]+R[l-1]-count);}
  }
}
