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

public class Main {

	public static class Pair{
		// indexじゃない
		public int start;
		public int end;
		Pair(int s, int e){
			start = s;
			end = e;
		}
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	}

} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {

	public static class Pair{
		// indexじゃない
		public int start;
		public int end;
		Pair(int s, int e){
			start = s;
			end = e;
		}
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int Q = Integer.parseInt(sc.next()); Q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String sline = sc.next(); sline 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] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		} {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		} l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc String[] s = new String[N]; s new String[N] N for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			s[i] = String.valueOf(sline.charAt(i));			
		} {
			s[i] = String.valueOf(sline.charAt(i));			
		} s[i] = String.valueOf(sline.charAt(i)) s[i] s i String.valueOf(sline.charAt(i)) String.valueOf String sline.charAt(i) sline.charAt sline i int[] ans = new int[N]; ans new int[N] N for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		} int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		} {
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		} if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			} s[i].equals("A") && s[i+1].equals("C") s[i].equals("A") s[i].equals s[i] s i "A" s[i+1].equals("C") s[i+1].equals s[i+1] s i+1 i 1 "C" {
				ans[i+1] = ans[i] + 1; 
			} ans[i+1] = ans[i] + 1 ans[i+1] ans i+1 i 1 ans[i] + 1 ans[i] ans i 1 {
				ans[i+1] = ans[i];
			} ans[i+1] = ans[i] ans[i+1] ans i+1 i 1 ans[i] ans i for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		} {
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		} System.out.println(ans[r[i]-1]-ans[l[i]-1]) System.out.println System.out System System.out ans[r[i]-1]-ans[l[i]-1] ans[r[i]-1] ans r[i]-1 r[i] r i 1 ans[l[i]-1] ans l[i]-1 l[i] l i 1 String[] args args public static class Pair{
		// indexじゃない
		public int start;
		public int end;
		Pair(int s, int e){
			start = s;
			end = e;
		}
	} Pair // indexじゃない
		public int start; start public int end; end Pair(int s, int e){
			start = s;
			end = e;
		} Pair {
			start = s;
			end = e;
		} start = s start s end = e end e int s s int e e public class Main {

	public static class Pair{
		// indexじゃない
		public int start;
		public int end;
		Pair(int s, int e){
			start = s;
			end = e;
		}
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	}

} public class Main {

	public static class Pair{
		// indexじゃない
		public int start;
		public int end;
		Pair(int s, int e){
			start = s;
			end = e;
		}
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	}

} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static class Pair{
		// indexじゃない
		public int start;
		public int end;
		Pair(int s, int e){
			start = s;
			end = e;
		}
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String sline = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i=0; i<Q; i++){
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		String[] s = new String[N];
		for (int i=0; i<N; i++){
			s[i] = String.valueOf(sline.charAt(i));			
		}
		// 0からi-1番目までのACのかず;
		int[] ans = new int[N];
		
		for (int i=0; i<N-1; i++){
			if(s[i].equals("A") && s[i+1].equals("C")){
				ans[i+1] = ans[i] + 1; 
			} else {
				ans[i+1] = ans[i];
			}
		}
		
		for(int i=0; i<Q; i++){
			System.out.println(ans[r[i]-1]-ans[l[i]-1]);
		}
		
	}

}
