import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	}
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	} main {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	} 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 String s = sc.next(); s sc.next() sc.next sc List<String> list= new ArrayList<String>(Arrays.asList(s.split(""))); list new ArrayList<String>(Arrays.asList(s.split(""))) int[] ac = new int[n+1]; ac new int[n+1] n+1 n 1 int count=0; count 0 for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        } int i=0; int i=0; i 0 n-1>i n-1 n 1 i i++ i++ i {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        } {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        } if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	} list.get(i).equals("A") list.get(i).equals list.get(i) list.get list i "A" {
        		if(list.get(i+1).equals("C"))
        			count++;
        	} if(list.get(i+1).equals("C"))
        			count++; list.get(i+1).equals("C") list.get(i+1).equals list.get(i+1) list.get list i+1 i 1 "C" count++ count ac[i+1] = count ac[i+1] ac i+1 i 1 count for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        } int i=0; int i=0; i 0 q>i q i i++ i++ i {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        } {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        } int a = sc.nextInt()-1; a sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int b = sc.nextInt()-1; b sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 System.out.println(ac[b]-ac[a]) System.out.println System.out System System.out ac[b]-ac[a] ac[b] ac b ac[a] ac a String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	}
} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
        int[] ac = new int[n+1];
        int count=0;
        for(int i=0;n-1>i;i++) {
        	if(list.get(i).equals("A")) {
        		if(list.get(i+1).equals("C"))
        			count++;
        	}
        	ac[i+1] = count;
        }
        //System.out.println(ac);
        //List<Integer> answer = new ArrayList<Integer>();
        for(int i=0;q>i;i++) {
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	System.out.println(ac[b]-ac[a]);
        }
        //System.out.println(answer);

	}
}