import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	}
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	}
} Main public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc char[] arr = sc.next().toCharArray(); arr sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] sums = new int[n]; sums new int[n] n for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		} {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		} if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    } arr[i - 1] == 'A' && arr[i] == 'C' arr[i - 1] == 'A' arr[i - 1] arr i - 1 i 1 'A' arr[i] == 'C' arr[i] arr i 'C' {
		        sums[i]++;
		    } sums[i]++ sums[i] sums i sums[i] += sums[i - 1] sums[i] sums i sums[i - 1] sums i - 1 i 1 StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		} {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		} int left = sc.nextInt(); left sc.nextInt() sc.nextInt sc int right = sc.nextInt(); right sc.nextInt() sc.nextInt sc int count = sums[right - 1] - sums[left - 1]; count sums[right - 1] - sums[left - 1] sums[right - 1] sums right - 1 right 1 sums[left - 1] sums left - 1 left 1 sb.append(count).append("\n") sb.append(count).append sb.append(count) sb.append sb count "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	}
} public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	}
} Main
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] sums = new int[n];
		for (int i = 1; i < n; i++) {
		    if (arr[i - 1] == 'A' && arr[i] == 'C') {
		        sums[i]++;
		    }
	        sums[i] += sums[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int count = sums[right - 1] - sums[left - 1];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
	}
}
