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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    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[] counts = new int[n + 1]; counts new int[n + 1] n + 1 n 1 for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		} int i = 2; int i = 2; i 2 i <= n i n i++ i++ i {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		} {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		} counts[i] = counts[i - 1] counts[i] counts i counts[i - 1] counts i - 1 i 1 if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    } arr[i - 2] == 'A' && arr[i - 1] == 'C' arr[i - 2] == 'A' arr[i - 2] arr i - 2 i 2 'A' arr[i - 1] == 'C' arr[i - 1] arr i - 1 i 1 'C' {
		        counts[i]++;
		    } counts[i]++ counts[i] counts i StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    sb.append(count).append("\n");
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    sb.append(count).append("\n");
		} {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    sb.append(count).append("\n");
		} int count = - counts[sc.nextInt()] + counts[sc.nextInt()]; count - counts[sc.nextInt()] + counts[sc.nextInt()] - counts[sc.nextInt()] counts[sc.nextInt()] counts sc.nextInt() sc.nextInt sc counts[sc.nextInt()] counts sc.nextInt() sc.nextInt sc 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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    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[] counts = new int[n + 1];
		for (int i = 2; i <= n; i++) {
		    counts[i] = counts[i - 1];
		    if (arr[i - 2] == 'A' && arr[i - 1] == 'C') {
		        counts[i]++;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int count = - counts[sc.nextInt()] + counts[sc.nextInt()];
		    sb.append(count).append("\n");
		}
		System.out.print(sb);
   }
}
