

import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	}

	static int n, q;
	static String s;
	static int sum[] = new int[maxn];

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	}
} import java.util.*; util.* java import java.math.*; math.* java import java.util.Scanner; Scanner java.util import java.math.BigInteger; BigInteger java.math public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	}

	static int n, q;
	static String s;
	static int sum[] = new int[maxn];

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	}
} Main static final long mod = (int) (1e9 + 7); mod (int) (1e9 + 7) 1e9 7 static final int inf = (int) (1e9); inf (int) (1e9) static final int maxn = (int) (1e5 + 10); maxn (int) (1e5 + 10) 1e5 10 static int n n q; q static String s; s static int sum[] = new int[maxn]; sum new int[maxn] maxn static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	} ksm {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	} long ret = 1; ret 1 while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		} b != 0 b 0 {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		} if (b % 2 == 1) {
				ret = ret * a % mod;
			} b % 2 == 1 b % 2 b 2 1 {
				ret = ret * a % mod;
			} ret = ret * a % mod ret ret * a % mod ret * a ret a mod b >>= 1 b 1 a = a * a % mod a a * a % mod a * a a a mod return ret; ret long a a long b b public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	} main {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	} Scanner cin = new Scanner(System.in); cin new Scanner(System.in) n = cin.nextInt() n cin.nextInt() cin.nextInt cin q = cin.nextInt() q cin.nextInt() cin.nextInt cin s = cin.next() s cin.next() cin.next cin for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		} {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		} sum[i+1] = sum[i] sum[i+1] sum i+1 i 1 sum[i] sum i if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			} s.charAt(i) == 'C' && s.charAt(i - 1) == 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' {
				sum[i+1]++;
			} sum[i+1]++ sum[i+1] sum i+1 i 1 for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		} int i = 1; int i = 1; i 1 i <= q i q i++ i++ i {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		} {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		} int l = cin.nextInt() l cin.nextInt() cin.nextInt cin r = cin.nextInt(); r cin.nextInt() cin.nextInt cin int ans = sum[r] - sum[l]; ans sum[r] - sum[l] sum[r] sum r sum[l] sum l System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	}

	static int n, q;
	static String s;
	static int sum[] = new int[maxn];

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	}
} public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	}

	static int n, q;
	static String s;
	static int sum[] = new int[maxn];

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	}
} Main


import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	}

	static int n, q;
	static String s;
	static int sum[] = new int[maxn];

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		q = cin.nextInt();
		s = cin.next();
		for (int i = 1; i < n; i++) {
			sum[i+1] = sum[i];
			if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
				sum[i+1]++;
			}
		}
		for (int i = 1; i <= q; i++) {
			int l = cin.nextInt(), r = cin.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	}
}