import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	int N, Q;
	String S;
	int[] l, r;
	List<Integer> acIndexes;
	int[] memo;
	PrintWriter out = new PrintWriter(System.out);

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	}

	void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.*; util.* java public class Main {
	int N, Q;
	String S;
	int[] l, r;
	List<Integer> acIndexes;
	int[] memo;
	PrintWriter out = new PrintWriter(System.out);

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	}

	void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	}

} Main int N N Q; Q String S; S int[] l l r; r List<Integer> acIndexes; acIndexes int[] memo; memo PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	} Main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String[] tokens = in.readLine().split(" "); tokens in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " N = Integer.parseInt(tokens[0]) N Integer.parseInt(tokens[0]) Integer.parseInt Integer tokens[0] tokens 0 Q = Integer.parseInt(tokens[1]) Q Integer.parseInt(tokens[1]) Integer.parseInt Integer tokens[1] tokens 1 S = in.readLine() S in.readLine() in.readLine in l = new int[Q] l new int[Q] Q r = new int[Q] r new int[Q] Q for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		} int i = 0; int i = 0; i 0 i < Q i Q ++i ++i i {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		} {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		} tokens = in.readLine().split(" ") tokens in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " l[i] = Integer.parseInt(tokens[0]) l[i] l i Integer.parseInt(tokens[0]) Integer.parseInt Integer tokens[0] tokens 0 r[i] = Integer.parseInt(tokens[1]) r[i] r i Integer.parseInt(tokens[1]) Integer.parseInt Integer tokens[1] tokens 1 in.close() in.close in void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	} calc {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	} this.memo = new int[N] this.memo this this.memo new int[N] N Arrays.fill(this.memo, 0) Arrays.fill Arrays this.memo this this.memo 0 int count = 0; count 0 char[] c = S.toCharArray(); c S.toCharArray() S.toCharArray S for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		} int i = 0; int i = 0; i 0 i < c.length - 1 i c.length - 1 c.length c c.length 1 ++i ++i i {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		} {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		} if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			} c[i] == 'A' && c[i + 1] == 'C' c[i] == 'A' c[i] c i 'A' c[i + 1] == 'C' c[i + 1] c i + 1 i 1 'C' {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} ++count count this.memo[i] = count this.memo[i] this.memo this this.memo i count this.memo[i + 1] = count this.memo[i + 1] this.memo this this.memo i + 1 i 1 count ++i i {
				this.memo[i] = count;
			} this.memo[i] = count this.memo[i] this.memo this this.memo i count this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2] this.memo[this.memo.length - 1] this.memo this this.memo this.memo.length - 1 this.memo.length this.memo this this.memo this.memo.length 1 this.memo[this.memo.length - 2] this.memo this this.memo this.memo.length - 2 this.memo.length this.memo this this.memo this.memo.length 2 for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		} int i = 0; int i = 0; i 0 i < Q i Q ++i ++i i {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		} {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		} int left = 0; left 0 if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			} l[i] == 1 l[i] l i 1 {
				left = 0;
			} left = 0 left 0 {
				left = this.memo[l[i] - 2];
			} left = this.memo[l[i] - 2] left this.memo[l[i] - 2] this.memo this this.memo l[i] - 2 l[i] l i 2 int right = this.memo[r[i] - 2]; right this.memo[r[i] - 2] this.memo this this.memo r[i] - 2 r[i] r i 2 int result = right - left; result right - left right left out.println(result) out.println out result public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	} main {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	} Main ins = new Main(); ins new Main() ins.calc() ins.calc ins ins.out.flush() ins.out.flush ins.out ins ins.out String[] args args public class Main {
	int N, Q;
	String S;
	int[] l, r;
	List<Integer> acIndexes;
	int[] memo;
	PrintWriter out = new PrintWriter(System.out);

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	}

	void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	}

} public class Main {
	int N, Q;
	String S;
	int[] l, r;
	List<Integer> acIndexes;
	int[] memo;
	PrintWriter out = new PrintWriter(System.out);

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	}

	void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	int N, Q;
	String S;
	int[] l, r;
	List<Integer> acIndexes;
	int[] memo;
	PrintWriter out = new PrintWriter(System.out);

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	}

	void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	}

}