import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    } 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 b = sc.next(); b sc.next() sc.next sc int[] count = new int[n+1]; count new int[n+1] n+1 n 1 for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        } int i = 1; int i = 1; i 1 i < n i n i ++ i ++ i {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        } {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        } int p = i+1; p i+1 i 1 if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            } b.charAt(i-1) == 'A' && b.charAt(i) == 'C' b.charAt(i-1) == 'A' b.charAt(i-1) b.charAt b i-1 i 1 'A' b.charAt(i) == 'C' b.charAt(i) b.charAt b i 'C' {
                count[p] = count[p-1] + 1;
            } count[p] = count[p-1] + 1 count[p] count p count[p-1] + 1 count[p-1] count p-1 p 1 1 {
                count[p] = count[p-1];
            } count[p] = count[p-1] count[p] count p count[p-1] count p-1 p 1 for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc 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) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

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