import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String str = sc.next();
		int a[] = new int[n];
		int x = 0;
		boolean hantei = false;
		
		for(int i = 0; i < n; i++){
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		}
		
		for(int i = 0; i < q; i++){
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String str = sc.next();
		int a[] = new int[n];
		int x = 0;
		boolean hantei = false;
		
		for(int i = 0; i < n; i++){
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		}
		
		for(int i = 0; i < q; i++){
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		}
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String str = sc.next();
		int a[] = new int[n];
		int x = 0;
		boolean hantei = false;
		
		for(int i = 0; i < n; i++){
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		}
		
		for(int i = 0; i < q; i++){
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String str = sc.next();
		int a[] = new int[n];
		int x = 0;
		boolean hantei = false;
		
		for(int i = 0; i < n; i++){
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		}
		
		for(int i = 0; i < q; i++){
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		}
	} 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 String str = sc.next(); str sc.next() sc.next sc int a[] = new int[n]; a new int[n] n int x = 0; x 0 boolean hantei = false; hantei false for(int i = 0; i < n; i++){
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		} {
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		} char c = str.charAt(i); c str.charAt(i) str.charAt str i if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			} c == 'A' c 'A' {
				a[i] = x;
				hantei = true;
			} a[i] = x a[i] a i x hantei = true hantei true if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			} hantei && (c == 'C') hantei (c == 'C') c 'C' {
				x += 1;
				a[i] = x;
				hantei = false;
			} x += 1 x 1 a[i] = x a[i] a i x hantei = false hantei false {
				a[i] = x;
				hantei = false;
			} a[i] = x a[i] a i x hantei = false hantei false for(int i = 0; i < q; i++){
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		} {
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		} int kekka = 0; kekka 0 int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc kekka = a[r-1] - a[l-1] kekka a[r-1] - a[l-1] a[r-1] a r-1 r 1 a[l-1] a l-1 l 1 System.out.println(kekka) System.out.println System.out System System.out kekka String args[] args
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String str = sc.next();
		int a[] = new int[n];
		int x = 0;
		boolean hantei = false;
		
		for(int i = 0; i < n; i++){
			char c = str.charAt(i);
			if(c == 'A'){
				a[i] = x;
				hantei = true;
			}else if(hantei && (c == 'C')){
				x += 1;
				a[i] = x;
				hantei = false;
			}else{
				a[i] = x;
				hantei = false;
			}
		}
		
		for(int i = 0; i < q; i++){
			int kekka = 0;
			int l = sc.nextInt();
			int r = sc.nextInt();
			kekka = a[r-1] - a[l-1];
			System.out.println(kekka);
		}
	}
}