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