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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str[] = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int q = Integer.parseInt(str[1]); q Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 String s[] = br.readLine().split(""); s br.readLine().split("") br.readLine().split br.readLine() br.readLine br "" int sum[] = new int[n]; sum new int[n] n for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		} {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		} if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			} s[i].equals("C") && s[i - 1].equals("A") s[i].equals("C") s[i].equals s[i] s i "C" s[i - 1].equals("A") s[i - 1].equals s[i - 1] s i - 1 i 1 "A" {
				sum[i] = sum[i - 1] + 1;
			} sum[i] = sum[i - 1] + 1 sum[i] sum i sum[i - 1] + 1 sum[i - 1] sum i - 1 i 1 1 {
				sum[i] = sum[i - 1];
			} sum[i] = sum[i - 1] sum[i] sum i sum[i - 1] sum i - 1 i 1 for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		} {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		} str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int l = Integer.parseInt(str[0]) - 1; l Integer.parseInt(str[0]) - 1 Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 1 int r = Integer.parseInt(str[1]) - 1; r Integer.parseInt(str[1]) - 1 Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 1 System.out.println(sum[r] - sum[l]) System.out.println System.out System System.out sum[r] - sum[l] sum[r] sum r sum[l] sum l String args[] args public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	}
} public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		String s[] = br.readLine().split("");

		int sum[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i].equals("C") && s[i - 1].equals("A")) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]) - 1;
			int r = Integer.parseInt(str[1]) - 1;

			System.out.println(sum[r] - sum[l]);
		}
	}
}
