
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	}

	private int getLength(String wk, int currentI, int total) {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	}

	private void solveB() {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	}

	private int getLengthC(String wk, int currentI, int total) {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	}

	Pattern p = Pattern.compile("AC");

	/**
	 * 高速置換
	 * @param original
	 * @param old
	 * @param replace
	 * @return
	 */
	private String replaceByHand(final String original, final String old, final String replace) {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	}

	/**
	 * 遅すぎる
	 * @param wk
	 * @param start
	 * @param last
	 * @return
	 */
	private int getLengthC2(String wk, int start, int last) {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	}

	private void solveC() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	}

	/**
	 * 11111122222233333333444444444555555555
	 *        ↑               ↑
	 *        4 - 2
	 *    ↑                   ↑
	 *        4 - 1
	 *       ↑                ↑
	 *        4 - 1
	 *
	 */
	private void solveC3() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
} import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.NoSuchElementException; NoSuchElementException java.util import java.util.regex.Pattern; Pattern java.util.regex public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	}

	private int getLength(String wk, int currentI, int total) {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	}

	private void solveB() {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	}

	private int getLengthC(String wk, int currentI, int total) {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	}

	Pattern p = Pattern.compile("AC");

	/**
	 * 高速置換
	 * @param original
	 * @param old
	 * @param replace
	 * @return
	 */
	private String replaceByHand(final String original, final String old, final String replace) {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	}

	/**
	 * 遅すぎる
	 * @param wk
	 * @param start
	 * @param last
	 * @return
	 */
	private int getLengthC2(String wk, int start, int last) {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	}

	private void solveC() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	}

	/**
	 * 11111122222233333333444444444555555555
	 *        ↑               ↑
	 *        4 - 2
	 *    ↑                   ↑
	 *        4 - 1
	 *       ↑                ↑
	 *        4 - 1
	 *
	 */
	private void solveC3() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
} Main Pattern p = Pattern.compile("AC"); p Pattern.compile("AC") Pattern.compile Pattern "AC" private final PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) private final InputStream in = System.in; in System.in System System.in private final byte[] buffer = new byte[1024]; buffer new byte[1024] 1024 private int ptr = 0; ptr 0 private int buflen = 0; buflen 0 public static void main(String[] args) throws IOException {
		new Main().solve();
	} main {
		new Main().solve();
	} new Main().solve() new Main().solve new Main() String[] args args private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	} solve {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	} try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		} {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		} if (in != null) {
				in.close();
			} in != null in null {
				in.close();
			} in.close() in.close in if (out != null) {
				out.flush();
				out.close();
			} out != null out null {
				out.flush();
				out.close();
			} out.flush() out.flush out out.close() out.close out {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} solveC3() solveC3 private void solveA() {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	} solveA {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	} String wk = next(); wk next() next if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		} wk.equals("A") wk.equals wk "A" {
			System.out.println("T");
		} System.out.println("T") System.out.println System.out System System.out "T" if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		} wk.equals("T") wk.equals wk "T" {
			System.out.println("A");
		} System.out.println("A") System.out.println System.out System System.out "A" if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		} wk.equals("G") wk.equals wk "G" {
			System.out.println("C");
		} System.out.println("C") System.out.println System.out System System.out "C" if (wk.equals("C")) {
			System.out.println("G");
		} wk.equals("C") wk.equals wk "C" {
			System.out.println("G");
		} System.out.println("G") System.out.println System.out System System.out "G" private int getLength(String wk, int currentI, int total) {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	} getLength {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	} if (currentI >= wk.length()) {
			return total;
		} currentI >= wk.length() currentI wk.length() wk.length wk {
			return total;
		} return total; total String wkS = wk.substring(currentI, currentI + 1); wkS wk.substring(currentI, currentI + 1) wk.substring wk currentI currentI + 1 currentI 1 if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		} wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C") wkS.equals("G") wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C") wkS.equals("A") wkS.equals wkS "A" wkS.equals("T") wkS.equals wkS "T" wkS.equals("G") wkS.equals wkS "G" wkS.equals("C") wkS.equals wkS "C" {
			return getLength(wk, currentI + 1, total) + 1;
		} return getLength(wk, currentI + 1, total) + 1; getLength(wk, currentI + 1, total) + 1 getLength(wk, currentI + 1, total) getLength wk currentI + 1 currentI 1 total 1 {
			return total;
		} return total; total String wk wk int currentI currentI int total total private void solveB() {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	} solveB {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	} String s = next(); s next() next int res = 0; res 0 for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		} int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		} {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		} int wkRes = getLength(s, i, 0); wkRes getLength(s, i, 0) getLength s i 0 res = Math.max(wkRes, res) res Math.max(wkRes, res) Math.max Math wkRes res out.println(res) out.println out res private int getLengthC(String wk, int currentI, int total) {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	} getLengthC {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	} if (currentI >= wk.length() - 1) {
			return total;
		} currentI >= wk.length() - 1 currentI wk.length() - 1 wk.length() wk.length wk 1 {
			return total;
		} return total; total String wkS = wk.substring(currentI, currentI + 2); wkS wk.substring(currentI, currentI + 2) wk.substring wk currentI currentI + 2 currentI 2 if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		} wkS.equals("AC") wkS.equals wkS "AC" {
			return getLengthC(wk, currentI + 2, total) + 1;
		} return getLengthC(wk, currentI + 2, total) + 1; getLengthC(wk, currentI + 2, total) + 1 getLengthC(wk, currentI + 2, total) getLengthC wk currentI + 2 currentI 2 total 1 {
			return getLengthC(wk, currentI + 1, total);
		} return getLengthC(wk, currentI + 1, total); getLengthC(wk, currentI + 1, total) getLengthC wk currentI + 1 currentI 1 total String wk wk int currentI currentI int total total /**
	 * 高速置換
	 * @param original
	 * @param old
	 * @param replace
	 * @return
	 */
	private String replaceByHand(final String original, final String old, final String replace) {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	} replaceByHand {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	} int offset = 0; offset 0 StringBuilder builder = new StringBuilder(original.length()); builder new StringBuilder(original.length()) int index; index while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		} 0 <= (index = original.indexOf(old, offset)) 0 (index = original.indexOf(old, offset)) index original.indexOf(old, offset) original.indexOf original old offset {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		} builder.append(original, offset, index) builder.append builder original offset index builder.append(replace) builder.append builder replace offset = index + old.length() offset index + old.length() index old.length() old.length old builder.append(original, offset, original.length()) builder.append builder original offset original.length() original.length original return builder.toString(); builder.toString() builder.toString builder final String original original final String old old final String replace replace /**
	 * 遅すぎる
	 * @param wk
	 * @param start
	 * @param last
	 * @return
	 */
	private int getLengthC2(String wk, int start, int last) {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	} getLengthC2 {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	} int total = 0; total 0 char[] wkL = wk.toCharArray(); wkL wk.toCharArray() wk.toCharArray wk for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		} int i = start + 1; int i = start + 1; i start + 1 start 1 i < last i last {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		} {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		} if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			} wkL[i] == 'C' && wkL[i - 1] == 'A' wkL[i] == 'C' wkL[i] wkL i 'C' wkL[i - 1] == 'A' wkL[i - 1] wkL i - 1 i 1 'A' {
				total++;
				i += 2;
			} total++ total i += 2 i 2 {
				i++;
			} i++ i return total; total String wk wk int start start int last last private void solveC() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	} solveC {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	} int numN = nextInt(); numN nextInt() nextInt int numQ = nextInt(); numQ nextInt() nextInt String strS = next(); strS next() next int[][] wk = new int[numQ][2]; wk new int[numQ][2] numQ 2 for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		} int i = 0; int i = 0; i 0 i < wk.length i wk.length wk wk.length i++ i++ i {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		} {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		} wk[i][0] = nextInt() wk[i][0] wk[i] wk i 0 nextInt() nextInt wk[i][1] = nextInt() wk[i][1] wk[i] wk i 1 nextInt() nextInt for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		} int[] is wk {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		} {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		} int res = 0; res 0 res = getLengthC2(strS, is[0] - 1, is[1]) res getLengthC2(strS, is[0] - 1, is[1]) getLengthC2 strS is[0] - 1 is[0] is 0 1 is[1] is 1 System.out.println(res) System.out.println System.out System System.out res /**
	 * 11111122222233333333444444444555555555
	 *        ↑               ↑
	 *        4 - 2
	 *    ↑                   ↑
	 *        4 - 1
	 *       ↑                ↑
	 *        4 - 1
	 *
	 */
	private void solveC3() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	} solveC3 {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	} int numN = nextInt(); numN nextInt() nextInt int numQ = nextInt(); numQ nextInt() nextInt String strS = next(); strS next() next int[][] wk = new int[numQ][2]; wk new int[numQ][2] numQ 2 for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		} int i = 0; int i = 0; i 0 i < wk.length i wk.length wk wk.length i++ i++ i {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		} {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		} wk[i][0] = nextInt() wk[i][0] wk[i] wk i 0 nextInt() nextInt wk[i][1] = nextInt() wk[i][1] wk[i] wk i 1 nextInt() nextInt int[] wkA = new int[strS.length()]; wkA new int[strS.length()] strS.length() strS.length strS char[] wkL = strS.toCharArray(); wkL strS.toCharArray() strS.toCharArray strS int cnt = 0; cnt 0 for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		} int i = 1; int i = 1; i 1 i < strS.length() i strS.length() strS.length strS i++ i++ i {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		} {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		} if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			} wkL[i] == 'C' && wkL[i - 1] == 'A' wkL[i] == 'C' wkL[i] wkL i 'C' wkL[i - 1] == 'A' wkL[i - 1] wkL i - 1 i 1 'A' {
				cnt++;
			} cnt++ cnt wkA[i] = cnt wkA[i] wkA i cnt for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		} int[] is wk {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		} {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		} int start = is[0]; start is[0] is 0 int last = is[1]; last is[1] is 1 int total = wkA[last - 1] - wkA[start - 1]; total wkA[last - 1] - wkA[start - 1] wkA[last - 1] wkA last - 1 last 1 wkA[start - 1] wkA start - 1 start 1 System.out.println(total) System.out.println System.out System System.out total private void solveD() {
		int numN = nextInt();

		out.println("");
	} solveD {
		int numN = nextInt();

		out.println("");
	} int numN = nextInt(); numN nextInt() nextInt out.println("") out.println out "" private void solveE() {
		int numN = nextInt();

		out.println("");
	} solveE {
		int numN = nextInt();

		out.println("");
	} int numN = nextInt(); numN nextInt() nextInt out.println("") out.println out "" private void solveF() {
		int numN = nextInt();

		out.println("");
	} solveF {
		int numN = nextInt();

		out.println("");
	} int numN = nextInt(); numN nextInt() nextInt out.println("") out.println out "" private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	} hasNextByte {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	} if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		} ptr < buflen ptr buflen {
			return true;
		} return true; true {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		} ptr = 0 ptr 0 try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} IOException e {
				e.printStackTrace();
			} e.printStackTrace() e.printStackTrace e {
				buflen = in.read(buffer);
			} buflen = in.read(buffer) buflen in.read(buffer) in.read in buffer if (buflen <= 0) {
				return false;
			} buflen <= 0 buflen 0 {
				return false;
			} return false; false return true; true private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	} readByte {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	} if (hasNextByte())
			return buffer[ptr++];
		else
			return -1; hasNextByte() hasNextByte return buffer[ptr++]; buffer[ptr++] buffer ptr++ ptr return -1; -1 1 private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	} isPrintableChar {
		return 33 <= c && c <= 126;
	} return 33 <= c && c <= 126; 33 <= c && c <= 126 33 <= c 33 c c <= 126 c 126 int c c private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	} skipUnprintable {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	} while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++; hasNextByte() && !isPrintableChar(buffer[ptr]) hasNextByte() hasNextByte !isPrintableChar(buffer[ptr]) isPrintableChar(buffer[ptr]) isPrintableChar buffer[ptr] buffer ptr ptr++ ptr public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	} hasNext {
		skipUnprintable();
		return hasNextByte();
	} skipUnprintable() skipUnprintable return hasNextByte(); hasNextByte() hasNextByte public int nextInt() {
		return Integer.parseInt(next());
	} nextInt {
		return Integer.parseInt(next());
	} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	} next {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	} if (!hasNext())
			throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = readByte(); b readByte() readByte while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		} isPrintableChar(b) isPrintableChar b {
			sb.appendCodePoint(b);
			b = readByte();
		} sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	} nextLong {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	} if (!hasNext())
			throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() long n = 0; n 0 boolean minus = false; minus false int b = readByte(); b readByte() readByte if (b == '-') {
			minus = true;
			b = readByte();
		} b == '-' b '-' {
			minus = true;
			b = readByte();
		} minus = true minus true b = readByte() b readByte() readByte if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		} b < '0' || '9' < b b < '0' b '0' '9' < b '9' b {
			throw new NumberFormatException();
		} throw new NumberFormatException(); new NumberFormatException() while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		} true {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		} if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			} '0' <= b && b <= '9' '0' <= b '0' b b <= '9' b '9' {
				n *= 10;
				n += b - '0';
			} n *= 10 n 10 n += b - '0' n b - '0' b '0' if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			} b == -1 || !isPrintableChar(b) b == -1 b -1 1 !isPrintableChar(b) isPrintableChar(b) isPrintableChar b {
				return minus ? -n : n;
			} return minus ? -n : n; minus ? -n : n minus -n n n {
				throw new NumberFormatException();
			} throw new NumberFormatException(); new NumberFormatException() b = readByte() b readByte() readByte public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	}

	private int getLength(String wk, int currentI, int total) {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	}

	private void solveB() {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	}

	private int getLengthC(String wk, int currentI, int total) {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	}

	Pattern p = Pattern.compile("AC");

	/**
	 * 高速置換
	 * @param original
	 * @param old
	 * @param replace
	 * @return
	 */
	private String replaceByHand(final String original, final String old, final String replace) {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	}

	/**
	 * 遅すぎる
	 * @param wk
	 * @param start
	 * @param last
	 * @return
	 */
	private int getLengthC2(String wk, int start, int last) {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	}

	private void solveC() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	}

	/**
	 * 11111122222233333333444444444555555555
	 *        ↑               ↑
	 *        4 - 2
	 *    ↑                   ↑
	 *        4 - 1
	 *       ↑                ↑
	 *        4 - 1
	 *
	 */
	private void solveC3() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	}

	private int getLength(String wk, int currentI, int total) {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	}

	private void solveB() {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	}

	private int getLengthC(String wk, int currentI, int total) {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	}

	Pattern p = Pattern.compile("AC");

	/**
	 * 高速置換
	 * @param original
	 * @param old
	 * @param replace
	 * @return
	 */
	private String replaceByHand(final String original, final String old, final String replace) {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	}

	/**
	 * 遅すぎる
	 * @param wk
	 * @param start
	 * @param last
	 * @return
	 */
	private int getLengthC2(String wk, int start, int last) {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	}

	private void solveC() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	}

	/**
	 * 11111122222233333333444444444555555555
	 *        ↑               ↑
	 *        4 - 2
	 *    ↑                   ↑
	 *        4 - 1
	 *       ↑                ↑
	 *        4 - 1
	 *
	 */
	private void solveC3() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
} Main

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			//			solveC();
			solveC3();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String wk = next();
		if (wk.equals("A")) {
			System.out.println("T");
		} else if (wk.equals("T")) {
			System.out.println("A");
		} else if (wk.equals("G")) {
			System.out.println("C");
		} else if (wk.equals("C")) {
			System.out.println("G");
		}

	}

	private int getLength(String wk, int currentI, int total) {
		if (currentI >= wk.length()) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 1);
		if (wkS.equals("A") || wkS.equals("T") || wkS.equals("G") || wkS.equals("C")) {
			return getLength(wk, currentI + 1, total) + 1;
		} else {
			return total;
		}
	}

	private void solveB() {
		String s = next();
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			int wkRes = getLength(s, i, 0);
			res = Math.max(wkRes, res);
		}

		out.println(res);
	}

	private int getLengthC(String wk, int currentI, int total) {
		if (currentI >= wk.length() - 1) {
			return total;
		}
		String wkS = wk.substring(currentI, currentI + 2);
		if (wkS.equals("AC")) {
			return getLengthC(wk, currentI + 2, total) + 1;
		} else {
			return getLengthC(wk, currentI + 1, total);
		}
	}

	Pattern p = Pattern.compile("AC");

	/**
	 * 高速置換
	 * @param original
	 * @param old
	 * @param replace
	 * @return
	 */
	private String replaceByHand(final String original, final String old, final String replace) {
		int offset = 0;
		StringBuilder builder = new StringBuilder(original.length());
		int index;
		while (0 <= (index = original.indexOf(old, offset))) {
			builder.append(original, offset, index);
			builder.append(replace);
			offset = index + old.length();
		}
		builder.append(original, offset, original.length());
		return builder.toString();
	}

	/**
	 * 遅すぎる
	 * @param wk
	 * @param start
	 * @param last
	 * @return
	 */
	private int getLengthC2(String wk, int start, int last) {
		int total = 0;
		//		wk = wk.substring(start, last);

		/**
		 * p8
		 */
		char[] wkL = wk.toCharArray();
		for (int i = start + 1; i < last;) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				total++;
				i += 2;
			} else {
				i++;
			}
		}

		/**
		 * p7
		 */
		//		total = (wk.length() - replaceByHand(wk, "AC", "").length()) / 2;

		/**
		 * p6
		 */
		//		String[] wkL = wk.split("");
		//		for (int i = start + 1; i < last;) {
		//			if (wkL[i].equals("C") && wkL[i - 1].equals("A")) {
		//				total++;
		//				i += 2;
		//			} else {
		//				i++;
		//			}
		//		}

		/**
		 * p5
		 */
		//		total = (wk.length() - wk.replaceAll("AC", "").length()) / 2;

		/**
		 * 4
		 */
		//		Matcher m = p.matcher(wk);
		//		int s = 0;
		//		while (m.find(s)) {
		//			total++;
		//			s = m.end();
		//		}

		/**
		 * p2
		 */
		//		if (wk.lastIndexOf("AC") == 3) {
		//			total = wk.split("AC").length;
		//		} else {
		//			total = wk.split("AC").length - 1;
		//		}

		/**
		 * p1
		 */
		//		total = (wk.length() - wk.replace("AC", "").length()) / 2;

		/**
		 * p1
		 */
		//		int num = 0;
		//		while (num != -1) {
		//			num = wk.indexOf("AC");
		//			if (num != -1) {
		//				total++;
		//				wk = wk.substring(2, wk.length());
		//			}
		//		}
		return total;
	}

	private void solveC() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		for (int[] is : wk) {
			//			String wkS = strS.substring(is[0] - 1, is[1]);
			int res = 0;
			//			for (int i = 0; i < wkS.length(); i++) {
			//				String firstS = wkS.substring(i, i + 1);
			//				boolean isNextA = firstS.equals("A");
			//				int wkRes = 0;
			//				if (isNextA) {
			//					wkRes = getLengthC(wkS, i, 0);
			//				}
			//				res = Math.max(wkRes, res);
			//			}
			res = getLengthC2(strS, is[0] - 1, is[1]);
			System.out.println(res);
		}

	}

	/**
	 * 11111122222233333333444444444555555555
	 *        ↑               ↑
	 *        4 - 2
	 *    ↑                   ↑
	 *        4 - 1
	 *       ↑                ↑
	 *        4 - 1
	 *
	 */
	private void solveC3() {
		int numN = nextInt();
		int numQ = nextInt();
		String strS = next();
		int[][] wk = new int[numQ][2];

		for (int i = 0; i < wk.length; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		//最初にカウント用の配列を用意
		int[] wkA = new int[strS.length()];

		char[] wkL = strS.toCharArray();
		int cnt = 0;
		for (int i = 1; i < strS.length(); i++) {
			if (wkL[i] == 'C' && wkL[i - 1] == 'A') {
				cnt++;
			}
			wkA[i] = cnt;

		}
		for (int[] is : wk) {
			int start = is[0];
			int last = is[1];

			int total = wkA[last - 1] - wkA[start - 1];

			System.out.println(total);
		}

	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}