import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    }
} Main public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String s = sc.next(); s sc.next() sc.next sc 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] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] ac = new int[n]; ac new int[n] n int count = 0; count 0 for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        } 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'){
                count++;
            }
            ac[i+1] = count;
        } {
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        } if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            } 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' {
                count++;
            } count++ count ac[i+1] = count ac[i+1] ac i+1 i 1 count StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        } {
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        } sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator()) sb.append(ac[r[i]-1] - ac[l[i]-1]).append sb.append(ac[r[i]-1] - ac[l[i]-1]) sb.append sb ac[r[i]-1] - ac[l[i]-1] ac[r[i]-1] ac r[i]-1 r[i] r i 1 ac[l[i]-1] ac l[i]-1 l[i] l i 1 System.lineSeparator() System.lineSeparator System System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    }
} public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    }
}