import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
}
}
//end import java.util.*; util.* java public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
}
} Main public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
} main {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n=Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int q=Integer.parseInt(scan.next()); q Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan String s=scan.next(); s scan.next() scan.next scan int[] count=new int [n]; count new int [n] n Arrays.fill(count, 0) Arrays.fill Arrays count 0 for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		} int i=1; int i=1; i 1 i<n i n ++i ++i i {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		} {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		} if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			} s.charAt(i-1)=='A'&&s.charAt(i)=='C' s.charAt(i-1)=='A' s.charAt(i-1) s.charAt s i-1 i 1 'A' s.charAt(i)=='C' s.charAt(i) s.charAt s i 'C' {
					count[i]=count[i-1]+1;			
				} count[i]=count[i-1]+1 count[i] count i count[i-1]+1 count[i-1] count i-1 i 1 1 {
				count[i]=count[i-1];
			} count[i]=count[i-1] count[i] count i count[i-1] count i-1 i 1 int l l r; r int[] ans =new int [q]; ans new int [q] q for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		} int i=0; int i=0; i 0 i<q i q ++i ++i i {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		} {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		} l=Integer.parseInt(scan.next()) l Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan r=Integer.parseInt(scan.next()) r Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan ans[i]=count[r-1]-count[l-1] ans[i] ans i count[r-1]-count[l-1] count[r-1] count r-1 r 1 count[l-1] count l-1 l 1 for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		} int i=0; int i=0; i 0 i<q i q ++i ++i i {
			System.out.println(ans[i]);
		} {
			System.out.println(ans[i]);
		} System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i String[] args args public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
}
} public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
}
} Main
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int q=Integer.parseInt(scan.next());
		String s=scan.next();
		int[] count=new int [n];
		Arrays.fill(count, 0);
		//累積和
		for (int i=1;i<n;++i) {
			if (s.charAt(i-1)=='A'&&s.charAt(i)=='C') {
					count[i]=count[i-1]+1;			
				}
			else {
				count[i]=count[i-1];
			}
		}
		
		int l,r;
		int[] ans =new int [q];
		for (int i=0;i<q;++i) {
			l=Integer.parseInt(scan.next());
			r=Integer.parseInt(scan.next());
			ans[i]=count[r-1]-count[l-1];
			
		}
		
		for (int i=0;i<q;++i) {
			System.out.println(ans[i]);
		}
		
	
}
}
//end
