import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	}	

} import java.util.*; util.* java public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	}	

} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	} main {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	} int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String S = sc.next(); S sc.next() sc.next sc int [] l = new int [Q]; l new int [Q] Q int [] r = new int [N]; r new int [N] N int sum = 0; sum 0 for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		} 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') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		} {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		} if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			} 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' {
			
				sum++;
				r[i+1] += sum;
			
			} sum++ sum r[i+1] += sum r[i+1] r i+1 i 1 sum {
				r[i+1] += sum;
			} r[i+1] += sum r[i+1] r i+1 i 1 sum for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		} {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		} int start = sc.nextInt() - 1; start sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int fin = sc.nextInt() - 1; fin sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 l[i] = r[fin] - r[start] l[i] l i r[fin] - r[start] r[fin] r fin r[start] r start for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		} int T = 0; int T = 0; T 0 T < Q T Q T++ T++ T {
			System.out.println(l[T]);
		} {
			System.out.println(l[T]);
		} System.out.println(l[T]) System.out.println System.out System System.out l[T] l T String[] args args public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	}	

} public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	}	

} Main
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int [] l = new int [Q];
		int [] r = new int [N];
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			
			if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
			
				sum++;
				r[i+1] += sum;
			
			} 
			
			else {
				r[i+1] += sum;
			}
		
		}
		
		for (int i = 0; i < Q; i++) {
		
			int start = sc.nextInt() - 1;
			int fin = sc.nextInt() - 1;
			l[i] = r[fin] - r[start];
			
		}
		
		for (int T = 0; T < Q; T++) {
			System.out.println(l[T]);
		}

	}	

}