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[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	}
} 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[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	} 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[] s = sc.next().toCharArray(); s sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] a = new int[n]; a new int[n] n boolean flag = false; flag false for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		} {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		} if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			} flag {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			} if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false; s[i] == 'C' s[i] s i 'C' {
					a[i] += 1;
					flag = false;
				} a[i] += 1 a[i] a i 1 flag = false flag false if(s[i] == 'A') flag = true;
				else flag = false; s[i] == 'A' s[i] s i 'A' flag = true flag true flag = false flag false {
				if(s[i] == 'A') flag = true;
			} if(s[i] == 'A') flag = true; s[i] == 'A' s[i] s i 'A' flag = true flag true a[i] += (i>0)?a[i-1]:0 a[i] a i (i>0)?a[i-1]:0 (i>0) i 0 a[i-1] a i-1 i 1 0 int l = 0 l 0 r = 0; r 0 for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		} {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		} l = sc.nextInt()-1 l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 r = sc.nextInt()-1 r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			} l == 0 l 0 {
				System.out.println(a[r]);
			} System.out.println(a[r]) System.out.println System.out System System.out a[r] a r {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			} n = (s[l]=='C'&&s[l-1]=='A')?1:0 n (s[l]=='C'&&s[l-1]=='A')?1:0 (s[l]=='C'&&s[l-1]=='A') s[l]=='C' s[l] s l 'C' s[l-1]=='A' s[l-1] s l-1 l 1 'A' 1 0 System.out.println(a[r]-a[l-1]-n) System.out.println System.out System System.out a[r]-a[l-1]-n a[r]-a[l-1]-n a[r] a r a[l-1] a l-1 l 1 n sc.close() sc.close sc 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[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	}
} 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[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	}
}