import java.util.Scanner;
 
public class Main {
 
    public static void main(String args[]) {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
 
    public static void main(String args[]) {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    }
} Main public static void main(String args[]) {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    } main {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Integer 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 Integer[] l = new Integer[q]; l new Integer[q] q Integer[] r = new Integer[q]; r new Integer[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[] count = new int[n]; count new int[n] n count[0] = 0 count[0] count 0 0 for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        } {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        } if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            } s.charAt(i) == 'C' && s.charAt(i - 1) == 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' {
                count[i] = count[i-1] + 1;
            } count[i] = count[i-1] + 1 count[i] count i count[i-1] + 1 count[i-1] count i-1 i 1 1 {
                count[i] = count[i-1];
            } count[i] = count[i-1] count[i] count i count[i-1] count i-1 i 1 String[] str = new String[q]; str new String[q] q for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        } {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        } int num = count[r[i] - 1] - count[l[i] - 1]; num count[r[i] - 1] - count[l[i] - 1] count[r[i] - 1] count r[i] - 1 r[i] r i 1 count[l[i] - 1] count l[i] - 1 l[i] l i 1 str[i] = Integer.toString(num) str[i] str i Integer.toString(num) Integer.toString Integer num System.out.println(String.join("\r\n", str)) System.out.println System.out System System.out String.join("\r\n", str) String.join String "\r\n" str sc.close() sc.close sc String args[] args public class Main {
 
    public static void main(String args[]) {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    }
} public class Main {
 
    public static void main(String args[]) {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    }
} Main
import java.util.Scanner;
 
public class Main {
 
    public static void main(String args[]) {
 
        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next()); // 未使用となる変数n
        Integer q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
 
        // 主処理
        int[] count = new int[n];
        count[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'A') {
                count[i] = count[i-1] + 1;
            } else {
                count[i] = count[i-1];
            }
        }
        String[] str = new String[q];
        for (int i = 0; i < q; i++) {
            int num = count[r[i] - 1] - count[l[i] - 1];
            str[i] = Integer.toString(num);
        }
 
        // 出力
        System.out.println(String.join("\r\n", str));
        sc.close();
    }
}