
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	}

} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Map.Entry; Entry java.util.Map import java.util.PriorityQueue; PriorityQueue java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	}

} Main public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	} main {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] tmp = scanner.nextLine().split(" "); tmp scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int n        = Integer.parseInt(tmp[0]); n Integer.parseInt(tmp[0]) Integer.parseInt Integer tmp[0] tmp 0 int q        = Integer.parseInt(tmp[1]); q Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 char[] s     = scanner.nextLine().toCharArray(); s scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner int[]  sum   = new int[n]; sum new int[n] n for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		} {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		} if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			} s[i - 1] == 'A' && s[i] =='C' s[i - 1] == 'A' s[i - 1] s i - 1 i 1 'A' s[i] =='C' s[i] s i 'C' {

				sum[i]++;
			} sum[i]++ sum[i] sum i sum[i] += sum[i - 1] sum[i] sum i sum[i - 1] sum i - 1 i 1 for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		} int i = 0; int i = 0; i 0 i < q i q i++ i++ i {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		} {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		} int a = scanner.nextInt() - 1; a scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 int b = scanner.nextInt() - 1; b scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 System.out.println(sum[b] - sum[a]) System.out.println System.out System System.out sum[b] - sum[a] sum[b] sum b sum[a] sum a String[] args args public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	}

} public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	}

} Main

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		int q        = Integer.parseInt(tmp[1]);
		char[] s     = scanner.nextLine().toCharArray();
		int[]  sum   = new int[n];


		for(int i = 1; i < n; i++) {

			if(s[i - 1] == 'A' && s[i] =='C') {

				sum[i]++;
			}

			sum[i] += sum[i - 1];
		}

		for(int i = 0; i < q; i++) {

			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;

			System.out.println(sum[b] - sum[a]);
		}

	}

}
