import java.util.Scanner;

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt(),q=sc.nextInt();
		char[] str = sc.next().toCharArray();
		int[] flag = new int[n];
		int count = 0;
		for(int i=1;i<n;i++) {
			if(str[i-1]=='A' &&  str[i]=='C') count++;
			flag[i]=count;
		}
		for(int i=0;i<q;i++) {
			int l = sc.nextInt()-1, r = sc.nextInt()-1, ans;
			ans=flag[r]-flag[l];
			//if(r<n-1 && str[r]=='A' && str[r+1]=='C') ans--;
          	//if(str[l]=='A') ans++;
			System.out.println(ans);
		}
	}
}