import java.util.Scanner;

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

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	}
} Main public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	} main {
		Main main = new Main();
		main.solve();
	} Main main = new Main(); main new Main() main.solve() main.solve main String[] args args void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	} solve {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] cnt = new int[n]; cnt new int[n] n for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		} {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		} cnt[i]=cnt[i-1] cnt[i] cnt i cnt[i-1] cnt i-1 i 1 if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			} c[i-1]=='A'&&c[i]=='C' c[i-1]=='A' c[i-1] c i-1 i 1 'A' c[i]=='C' c[i] c i 'C' {
				cnt[i]++;
			} cnt[i]++ cnt[i] cnt i StringBuilder buf = new StringBuilder(); buf new StringBuilder() String s ="\n"; s "\n" for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		} int i=0; int i=0; i 0 i<q i q i++ i++ i {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		} {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		} int L = Integer.parseInt(sc.next())-1; L Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 int R = Integer.parseInt(sc.next())-1; R Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 buf.append((cnt[R]-cnt[L])+s) buf.append buf (cnt[R]-cnt[L])+s (cnt[R]-cnt[L]) cnt[R] cnt R cnt[L] cnt L s sc.close() sc.close sc System.out.println(buf) System.out.println System.out System System.out buf public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	}
} public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	}
} Main
import java.util.Scanner;

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

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int[] cnt = new int[n];
		for(int i=1;i<n;i++) {
			cnt[i]=cnt[i-1];
			if(c[i-1]=='A'&&c[i]=='C') {
				cnt[i]++;
			}
		}
		StringBuilder buf = new StringBuilder();
		String s ="\n";

		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			buf.append((cnt[R]-cnt[L])+s);
		}
		sc.close();
		System.out.println(buf);
	}
}
