import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_2020_0217_003();
	}


	public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	}
} import java.util.Scanner; Scanner java.util public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_2020_0217_003();
	}


	public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args){

		solve_2020_0217_003();
	} main {

		solve_2020_0217_003();
	} solve_2020_0217_003() solve_2020_0217_003 String[] args args public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	} solve_2020_0217_003 {

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	} 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 String kw = "AC"; kw "AC" int[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int[] cs = new int[N+1]; cs new int[N+1] N+1 N 1 cs[0] = 0 cs[0] cs 0 0 cs[1] = 0 cs[1] cs 1 0 for(int i=1;i<N;i++){

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		} int i=1; int i=1; i 1 i<N i N i++ i++ i {

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		} {

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		} int cs_tmp = 0; cs_tmp 0 if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			} S.substring(i-1, i+1).equals(kw) S.substring(i-1, i+1).equals S.substring(i-1, i+1) S.substring S i-1 i 1 i+1 i 1 kw {
				cs_tmp = 1;
			} cs_tmp = 1 cs_tmp 1 cs[i+1] = cs[i] + cs_tmp cs[i+1] cs i+1 i 1 cs[i] + cs_tmp cs[i] cs i cs_tmp for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		} int i=0; int i=0; i 0 i<Q i Q i++ i++ i {

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		} {

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		} int ans = cs[r[i]] - cs[l[i]]; ans cs[r[i]] - cs[l[i]] cs[r[i]] cs r[i] r i cs[l[i]] cs l[i] l i System.out.println(ans) System.out.println System.out System System.out ans public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_2020_0217_003();
	}


	public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	}
} public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_2020_0217_003();
	}


	public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	}
} Main
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_2020_0217_003();
	}


	public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

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

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	}
}