import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    } 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 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 int[] t = new int[n]; t new int[n] n for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        } {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        } t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i] t[i + 1] t i + 1 i 1 s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i] s.substring(i, i+2).equals("AC") s.substring(i, i+2).equals s.substring(i, i+2) s.substring s i i+2 i 2 "AC" t[i] + 1 t[i] t i 1 t[i] t i for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        } {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        } int res = t[r[i] - 1] - t[l[i] - 1]; res t[r[i] - 1] - t[l[i] - 1] t[r[i] - 1] t r[i] - 1 r[i] r i 1 t[l[i] - 1] t l[i] - 1 l[i] l i 1 System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

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

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    }
}
