import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
}


 import java.util.*; util.* java import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] nq = br.readLine().split(" "); nq br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(nq[0]); n Integer.parseInt(nq[0]) Integer.parseInt Integer nq[0] nq 0 int q = Integer.parseInt(nq[1]); q Integer.parseInt(nq[1]) Integer.parseInt Integer nq[1] nq 1 String s = br.readLine(); s br.readLine() br.readLine br int[] count = new int[n]; count new int[n] n int cnt = 0; cnt 0 for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        } {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        } if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            } s.charAt(i)=='A' && s.charAt(i+1)=='C' s.charAt(i)=='A' s.charAt(i) s.charAt s i 'A' s.charAt(i+1)=='C' s.charAt(i+1) s.charAt s i+1 i 1 'C' {
                cnt++;
            } cnt++ cnt count[i+1] = cnt count[i+1] count i+1 i 1 cnt for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        } {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        } String[] lr = br.readLine().split(" "); lr br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int l = Integer.parseInt(lr[0])-1; l Integer.parseInt(lr[0])-1 Integer.parseInt(lr[0]) Integer.parseInt Integer lr[0] lr 0 1 int r = Integer.parseInt(lr[1])-1; r Integer.parseInt(lr[1])-1 Integer.parseInt(lr[1]) Integer.parseInt Integer lr[1] lr 1 1 System.out.println(count[r]-count[l]) System.out.println System.out System System.out count[r]-count[l] count[r] count r count[l] count l String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
} Main
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
}



