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

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	} main {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	} BufferedReader bf = null; bf null bf = new BufferedReader(new InputStreamReader(System.in)) bf new BufferedReader(new InputStreamReader(System.in)) int n n q q l l r r ans; ans String str; str String[] s s stemp; stemp int[] list; list str = bf.readLine() str bf.readLine() bf.readLine bf stemp = str.split(" ") stemp str.split(" ") str.split str " " n = Integer.parseInt(stemp[0]) n Integer.parseInt(stemp[0]) Integer.parseInt Integer stemp[0] stemp 0 q = Integer.parseInt(stemp[1]) q Integer.parseInt(stemp[1]) Integer.parseInt Integer stemp[1] stemp 1 list = new int[n] list new int[n] n str = bf.readLine() str bf.readLine() bf.readLine bf s = str.split("") s str.split("") str.split str "" if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		} s[0].equals("A") && s[1].equals("C") s[0].equals("A") s[0].equals s[0] s 0 "A" s[1].equals("C") s[1].equals s[1] s 1 "C" {
			list[0] = 1;
		} list[0] = 1 list[0] list 0 1 for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		} int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 ++i ++i i {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		} {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		} if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			} s[i].equals("A") && s[i+1].equals("C") s[i].equals("A") s[i].equals s[i] s i "A" s[i+1].equals("C") s[i+1].equals s[i+1] s i+1 i 1 "C" {
				list[i] = list[i-1] + 1;
			} list[i] = list[i-1] + 1 list[i] list i list[i-1] + 1 list[i-1] list i-1 i 1 1 {
				list[i] = list[i-1];
			} list[i] = list[i-1] list[i] list i list[i-1] list i-1 i 1 list[n-1] = list[n-2] list[n-1] list n-1 n 1 list[n-2] list n-2 n 2 for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		} int i = 0; int i = 0; i 0 i < q i q ++i ++i i {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		} {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		} str = bf.readLine() str bf.readLine() bf.readLine bf stemp = str.split(" ") stemp str.split(" ") str.split str " " l = Integer.parseInt(stemp[0])-1 l Integer.parseInt(stemp[0])-1 Integer.parseInt(stemp[0]) Integer.parseInt Integer stemp[0] stemp 0 1 r = Integer.parseInt(stemp[1])-1 r Integer.parseInt(stemp[1])-1 Integer.parseInt(stemp[1]) Integer.parseInt Integer stemp[1] stemp 1 1 if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			} l == 0 l 0 {
				ans = list[r-1];
			} ans = list[r-1] ans list[r-1] list r-1 r 1 {
				ans = list[r-1] - list[l-1];
			} ans = list[r-1] - list[l-1] ans list[r-1] - list[l-1] list[r-1] list r-1 r 1 list[l-1] list l-1 l 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	}
} public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	}
} Main

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

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	}
}