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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	}
} 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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	}
} 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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	} 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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	} 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 for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		} {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		} if(s[i-1]=='A'&&s[i]=='C') a[i] += 1; s[i-1]=='A'&&s[i]=='C' s[i-1]=='A' s[i-1] s i-1 i 1 'A' s[i]=='C' s[i] s i 'C' a[i] += 1 a[i] a i 1 a[i] += a[i-1] a[i] a i a[i-1] a i-1 i 1 int l = 0 l 0 r = 0; r 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		} {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		} l = Integer.parseInt(sc.next())-1 l Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 r = Integer.parseInt(sc.next())-1 r Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			} l == 0 l 0 {
				sb.append(a[r]);
			} sb.append(a[r]) sb.append sb a[r] a r {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(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 sb.append(a[r]-a[l-1]-n) sb.append sb 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 sb.append('\n') sb.append sb '\n' System.out.println(new String(sb)) System.out.println System.out System System.out new String(sb) 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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	}
} 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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	}
} 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];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	}
}