import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	}
		

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	}
		

} Main public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	} main {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	} try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		} {
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan long[] s = new long[N+1+1]; s new long[N+1+1] N+1+1 N+1+1 N 1 1 int Q = scan.nextInt(); Q scan.nextInt() scan.nextInt scan String S = scan.next(); S scan.next() scan.next scan char []c = new char[N]; c new char[N] N c = S.toCharArray() c S.toCharArray() S.toCharArray S 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] = scan.nextInt();
				r[i] = scan.nextInt();
			} int i = 0; int i = 0; i 0 i<Q i Q i++ i++ i {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			} {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			} l[i] = scan.nextInt() l[i] l i scan.nextInt() scan.nextInt scan r[i] = scan.nextInt() r[i] r i scan.nextInt() scan.nextInt scan for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			} {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			} if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			} i>=1 i 1 {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			} if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				} c[i]=='C'&&c[i-1]=='A' c[i]=='C' c[i] c i 'C' c[i-1]=='A' c[i-1] c i-1 i 1 'A' {
					s[i+1] = s[i]+1;
				} s[i+1] = s[i]+1 s[i+1] s i+1 i 1 s[i]+1 s[i] s i 1 {
					s[i+1] = s[i];
				} s[i+1] = s[i] s[i+1] s i+1 i 1 s[i] s i for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			} int i = 0; int i = 0; i 0 i<Q i Q i++ i++ i {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			} {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			} long a = s[r[i]]-s[l[i]]; a s[r[i]]-s[l[i]] s[r[i]] s r[i] r i s[l[i]] s l[i] l i System.out.println(a) System.out.println System.out System System.out a String[]args args public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	}
		

} public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	}
		

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			long[] s = new long[N+1+1];
			int Q = scan.nextInt();
			String S = scan.next();
			char []c = new char[N];
			c = S.toCharArray();
			int []l = new int[Q];
			int []r = new int[Q];
			for(int i = 0;i<Q;i++) {
				l[i] = scan.nextInt();
				r[i] = scan.nextInt();
			}
			
			for(int i = 0;i<N;i++) {
				if(i>=1) {
				if(c[i]=='C'&&c[i-1]=='A') {
					s[i+1] = s[i]+1;
				}else {
					s[i+1] = s[i];
				}
				
			}
				//System.out.println(s[i+1]);
			}
				
			for(int i = 0;i<Q;i++) {	
				long a = s[r[i]]-s[l[i]];
				System.out.println(a);
			}
			
			
			
			
		}
		
		
	}
		

}
