import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

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

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

	}
} Main public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

	} main {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N=Integer.parseInt(scanner.next()); N Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int Q=Integer.parseInt(scanner.next()); Q Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner String S =scanner.next(); S scanner.next() scanner.next scanner S=S.replaceAll("AC", "aC") S S.replaceAll("AC", "aC") S.replaceAll S "AC" "aC" int[] L=new int[Q]; L new int[Q] Q int[] R=new int[Q]; R new int[Q] Q int[] t = new int[N+1]; t new int[N+1] N+1 N 1 for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    } {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    } L[i]=Integer.parseInt(scanner.next()) L[i] L i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner R[i]=Integer.parseInt(scanner.next()) R[i] R i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int c= 0; c 0 t[0]=0 t[0] t 0 0 for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    } {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    } if (S.charAt(i) == 'a') {
	    	    c++;
	    	} S.charAt(i) == 'a' S.charAt(i) S.charAt S i 'a' {
	    	    c++;
	    	} c++ c t[i+1]=c t[i+1] t i+1 i 1 c for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    } {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    } int ca=t[R[i]-1] - t[L[i]-1]; ca t[R[i]-1] - t[L[i]-1] t[R[i]-1] t R[i]-1 R[i] R i 1 t[L[i]-1] t L[i]-1 L[i] L i 1 System.out.println(ca) System.out.println System.out System System.out ca String[] args args public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

	}
} public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N=Integer.parseInt(scanner.next());
	    int Q=Integer.parseInt(scanner.next());
	    String S =scanner.next();
	    S=S.replaceAll("AC", "aC");
	    int[] L=new int[Q];
	    int[] R=new int[Q];
	    int[] t = new int[N+1];

	    for(int i=0; i<Q;i++) {
	    	L[i]=Integer.parseInt(scanner.next());
	    	R[i]=Integer.parseInt(scanner.next());
	    }

	    int c= 0;
	    t[0]=0;
	    for (int i=0; i<N;i++) {
	    	if (S.charAt(i) == 'a') {
	    	    c++;
	    	}
	    	t[i+1]=c;
	    }

	    for (int i=0; i<Q; i++) {
	    	int ca=t[R[i]-1] - t[L[i]-1];


	    	System.out.println(ca);
	    }

	}
}