import 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 str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    }
} import java.util.*; util.* java 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 str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    }
} 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 str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    } 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 str = sc.next(); str sc.next() sc.next sc int[] s = new int[N+1]; s new int[N+1] N+1 N 1 for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        } int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        } {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        } if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            } i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C' i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C' i != N-1 i N-1 N 1 str.charAt(i) == 'A' str.charAt(i) str.charAt str i 'A' str.charAt(i+1) == 'C' str.charAt(i+1) str.charAt str i+1 i 1 'C' {
                s[i+1] = s[i] + 1;
            } s[i+1] = s[i] + 1 s[i+1] s i+1 i 1 s[i] + 1 s[i] s i 1 {
                s[i+1] = s[i];
            } s[i+1] = s[i] s[i+1] s i+1 i 1 s[i] s i for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        } int i = 0; int i = 0; i 0 i < Q i Q ++i ++i i {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        } {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        } int l = Integer.parseInt(sc.next()); l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r = Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc System.out.println(s[r-1] - s[l-1]) System.out.println System.out System System.out s[r-1] - s[l-1] s[r-1] s r-1 r 1 s[l-1] s l-1 l 1 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 str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    }
} 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 str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    }
} Main
import 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 str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    }
}