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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	}
	
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	}
	
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int N = Integer.parseInt(st.nextToken()); N Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int Q = Integer.parseInt(st.nextToken()); Q Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st String S = br.readLine(); S br.readLine() br.readLine br int[] a = new int[N]; a new int[N] N for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		} int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		} {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		} if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++; S.charAt(i) == 'A' && S.charAt(i+1) == 'C' S.charAt(i) == 'A' S.charAt(i) S.charAt S i 'A' S.charAt(i+1) == 'C' S.charAt(i+1) S.charAt S i+1 i 1 'C' a[i+1]++ a[i+1] a i+1 i 1 int[] psa = new int[N]; psa new int[N] N psa[0] = a[0] psa[0] psa 0 a[0] a 0 for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
			psa[i] = psa[i-1] + a[i];
		} {
			psa[i] = psa[i-1] + a[i];
		} psa[i] = psa[i-1] + a[i] psa[i] psa i psa[i-1] + a[i] psa[i-1] psa i-1 i 1 a[i] a i while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		} Q-->0 Q-- Q 0 {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		} st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) int l = Integer.parseInt(st.nextToken()) l Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st r = Integer.parseInt(st.nextToken()); r Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st System.out.println(psa[r-1]-psa[l-1]) System.out.println System.out System System.out psa[r-1]-psa[l-1] psa[r-1] psa r-1 r 1 psa[l-1] psa l-1 l 1 String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	}
	
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	}
	
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int[] a = new int[N];
		for (int i = 0; i < N-1; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') a[i+1]++;
		}
		int[] psa = new int[N];
		psa[0] = a[0];
		for (int i = 1; i < N; i++) {
			psa[i] = psa[i-1] + a[i];
		}
		while (Q-->0) {
			st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken());
			System.out.println(psa[r-1]-psa[l-1]);
		}
	}
	
}