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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Q = Integer.parseInt(strArr[1]);
	}

	int Q;

	public void readS(String str) {
		CNT = new int[N + 1];
		CNT[1] = 0;
		for (int i = 1; i < N; i++) {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		}
	}

	int[] CNT;

	public boolean hasNext() {
		// return cnt < N;
		return cnt < Q;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int l = Integer.parseInt(strArr[0]);
		int r = Integer.parseInt(strArr[1]);
		System.out.println((CNT[r] - CNT[l]));
		cnt++;
	}

	public void solve() {

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) Solver solver = new Solver(); solver new Solver() solver.init() solver.init solver solver.readHead(in.readLine()) solver.readHead solver in.readLine() in.readLine in solver.readS(in.readLine()) solver.readS solver in.readLine() in.readLine in for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		} ; solver.hasNext() solver.hasNext solver {
			solver.readBody(in.readLine());
		} {
			solver.readBody(in.readLine());
		} solver.readBody(in.readLine()) solver.readBody solver in.readLine() in.readLine in solver.solve() solver.solve solver String args[] args class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Q = Integer.parseInt(strArr[1]);
	}

	int Q;

	public void readS(String str) {
		CNT = new int[N + 1];
		CNT[1] = 0;
		for (int i = 1; i < N; i++) {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		}
	}

	int[] CNT;

	public boolean hasNext() {
		// return cnt < N;
		return cnt < Q;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int l = Integer.parseInt(strArr[0]);
		int r = Integer.parseInt(strArr[1]);
		System.out.println((CNT[r] - CNT[l]));
		cnt++;
	}

	public void solve() {

	}
} Solver int N; N int cnt; cnt int Q; Q int[] CNT; CNT public void init() {
		N = 0;
		cnt = 0;
	} init {
		N = 0;
		cnt = 0;
	} N = 0 N 0 cnt = 0 cnt 0 public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Q = Integer.parseInt(strArr[1]);
	} readHead {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Q = Integer.parseInt(strArr[1]);
	} String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " N = Integer.parseInt(strArr[0]) N Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 Q = Integer.parseInt(strArr[1]) Q Integer.parseInt(strArr[1]) Integer.parseInt Integer strArr[1] strArr 1 String str str public void readS(String str) {
		CNT = new int[N + 1];
		CNT[1] = 0;
		for (int i = 1; i < N; i++) {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		}
	} readS {
		CNT = new int[N + 1];
		CNT[1] = 0;
		for (int i = 1; i < N; i++) {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		}
	} CNT = new int[N + 1] CNT new int[N + 1] N + 1 N 1 CNT[1] = 0 CNT[1] CNT 1 0 for (int i = 1; i < N; i++) {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.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 (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		} {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		} CNT[i + 1] = CNT[i] CNT[i + 1] CNT i + 1 i 1 CNT[i] CNT i if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			} str.charAt(i - 1) == 'A' && str.charAt(i) == 'C' str.charAt(i - 1) == 'A' str.charAt(i - 1) str.charAt str i - 1 i 1 'A' str.charAt(i) == 'C' str.charAt(i) str.charAt str i 'C' {
				CNT[i + 1]++;
			} CNT[i + 1]++ CNT[i + 1] CNT i + 1 i 1 String str str public boolean hasNext() {
		// return cnt < N;
		return cnt < Q;
	} hasNext {
		// return cnt < N;
		return cnt < Q;
	} return cnt < Q; cnt < Q cnt Q public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int l = Integer.parseInt(strArr[0]);
		int r = Integer.parseInt(strArr[1]);
		System.out.println((CNT[r] - CNT[l]));
		cnt++;
	} readBody {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int l = Integer.parseInt(strArr[0]);
		int r = Integer.parseInt(strArr[1]);
		System.out.println((CNT[r] - CNT[l]));
		cnt++;
	} String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " int l = Integer.parseInt(strArr[0]); l Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 int r = Integer.parseInt(strArr[1]); r Integer.parseInt(strArr[1]) Integer.parseInt Integer strArr[1] strArr 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 cnt++ cnt String str str public void solve() {

	} solve {

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Q = Integer.parseInt(strArr[1]);
	}

	int Q;

	public void readS(String str) {
		CNT = new int[N + 1];
		CNT[1] = 0;
		for (int i = 1; i < N; i++) {
			CNT[i + 1] = CNT[i];
			if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
				CNT[i + 1]++;
			}
		}
	}

	int[] CNT;

	public boolean hasNext() {
		// return cnt < N;
		return cnt < Q;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int l = Integer.parseInt(strArr[0]);
		int r = Integer.parseInt(strArr[1]);
		System.out.println((CNT[r] - CNT[l]));
		cnt++;
	}

	public void solve() {

	}
}
