import java.util.Scanner;
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 []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			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();
		int q = sc.nextInt();
		
		char []c = sc.next().toCharArray();
		int []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		}
		
		
		
	}

	} 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 []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		}
		
		
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		char []c = sc.next().toCharArray();
		int []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			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 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 []s = new int [n]; s new int [n] n s[0]  = 0 s[0] s 0 0 for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		} int i = 0 ; int i = 0 ; i 0 i < n-1 i n-1 n 1 i++ i++ i {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		} {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		} if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			} c[i] == 'A'&& c[i+1] == 'C' c[i] == 'A' c[i] c i 'A' c[i+1] == 'C' c[i+1] c i+1 i 1 'C' {
				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 j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		} int j = 0; int j = 0; j 0 j < q j q j++ j++ j {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int ans = s[r-1] - s[l-1]; ans s[r-1] - s[l-1] s[r-1] s r-1 r 1 s[l-1] s l-1 l 1 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();
		int q = sc.nextInt();
		
		char []c = sc.next().toCharArray();
		int []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		}
		
		
		
	}

	} 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 []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			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();
		int q = sc.nextInt();
		
		char []c = sc.next().toCharArray();
		int []s = new int [n];
		
		s[0]  = 0;
		
		for(int i = 0 ; i < n-1 ;i++) {
			if(c[i] == 'A'&& c[i+1] == 'C') {
				s[i+1] = s[i] + 1 ;
			}
			else {
				s[i+1] = s[i];
			}
				
		}
		
		for(int j = 0; j < q ; j++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = s[r-1] - s[l-1];
			System.out.println(ans);
		}
		
		
		
	}

	}

