import 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();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	} 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 s = sc.next(); s sc.next() sc.next sc int[] t = new int[n+1]; t new int[n+1] n+1 n 1 int i; i t[0]=0 t[0] t 0 0 for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		} i=1; i=1 i 1 i<n i n i++ i++ i {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		} {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		} t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0) t[i] t i t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0) t[i-1] t i-1 i 1 ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0) (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') s.charAt(i-1) == 'A' s.charAt(i-1) s.charAt s i-1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' 1 0 t[i] = t[i-1] t[i] t i t[i-1] t i-1 i 1 int l l r; r for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		} i=0; i=0 i 0 i<q i q i++ i++ i {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		} {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		} l=sc.nextInt() l sc.nextInt() sc.nextInt sc r=sc.nextInt() r sc.nextInt() sc.nextInt sc System.out.println(t[r-1]-t[l-1]) System.out.println System.out System System.out t[r-1]-t[l-1] t[r-1] t r-1 r 1 t[l-1] t l-1 l 1 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();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	}
} Main
import 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();
		String s = sc.next();
		int[] t = new int[n+1];
		int i;
		t[0]=0;
		for(i=1; i<n; i++) {
			t[i] = t[i-1] + ((s.charAt(i-1) == 'A' && s.charAt(i) == 'C')?1:0); 
		}
		t[i] = t[i-1];
		int l,r;
		for(i=0; i<q; i++) {
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(t[r-1]-t[l-1]);
		}
	}
}
