import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    }
} Main public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    } main {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    } Scanner input=new Scanner (System.in); input new Scanner (System.in) int n=input.nextInt(); n input.nextInt() input.nextInt input ArrayList <Integer>ind=new <Integer>ArrayList(); ind new <Integer>ArrayList() int q=input.nextInt(); q input.nextInt() input.nextInt input System.out.flush() System.out.flush System.out System System.out String str=input.next(); str input.next() input.next input int max=0; max 0 int co=0; co 0 int arr[]=new int[n]; arr new int[n] n arr[0]=0 arr[0] arr 0 0 for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        } {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        } if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co; str.charAt(i-1)=='A'&& str.charAt(i)=='C' str.charAt(i-1)=='A' str.charAt(i-1) str.charAt str i-1 i 1 'A' str.charAt(i)=='C' str.charAt(i) str.charAt str i 'C' {
                ind.add(i);
                co++;
                arr[i]=co;
            } ind.add(i) ind.add ind i co++ co arr[i]=co arr[i] arr i co arr[i]=co arr[i] arr i co for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        } int i=0; int i=0; i 0 i<q i q i++ i++ i {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        } {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        } int l=input.nextInt(); l input.nextInt() input.nextInt input int r=input.nextInt(); r input.nextInt() input.nextInt input int count=arr[r-1]-arr[l-1]; count arr[r-1]-arr[l-1] arr[r-1] arr r-1 r 1 arr[l-1] arr l-1 l 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    }
}
