import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] sa = br.readLine().split(" "); sa br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(sa[0]); n Integer.parseInt(sa[0]) Integer.parseInt Integer sa[0] sa 0 int q = Integer.parseInt(sa[1]); q Integer.parseInt(sa[1]) Integer.parseInt Integer sa[1] sa 1 String s = br.readLine(); s br.readLine() br.readLine br int[] cnt = new int[n + 1]; cnt new int[n + 1] n + 1 n 1 for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		} {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		} cnt[i + 1] = cnt[i] cnt[i + 1] cnt i + 1 i 1 cnt[i] cnt i if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			} 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' {
				cnt[i + 1]++;
			} cnt[i + 1]++ cnt[i + 1] cnt i + 1 i 1 for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		} {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		} sa = br.readLine().split(" ") sa br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int l = Integer.parseInt(sa[0]); l Integer.parseInt(sa[0]) Integer.parseInt Integer sa[0] sa 0 int r = Integer.parseInt(sa[1]); r Integer.parseInt(sa[1]) Integer.parseInt Integer sa[1] sa 1 System.out.println(cnt[r] - cnt[l]) System.out.println System.out System System.out cnt[r] - cnt[l] cnt[r] cnt r cnt[l] cnt l br.close() br.close br String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		String s = br.readLine();
		int[] cnt = new int[n + 1];
		for (int i = 1; i < n; i++) {
			cnt[i + 1] = cnt[i];
			if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
				cnt[i + 1]++;
			}
		}
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]);
			int r = Integer.parseInt(sa[1]);
			System.out.println(cnt[r] - cnt[l]);
		}
		br.close();
	}
}
