// インデックスまでのAC数を数えて、
// rまでのAC数からlまでのAC数を引くことで求める
// 参考 -> #4701870

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();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

        for (int i : ans)
            System.out.println(i);
    }
} 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();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

        for (int i : ans)
            System.out.println(i);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

        for (int i : ans)
            System.out.println(i);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

        for (int i : ans)
            System.out.println(i);
    } 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 char[] s = sc.next().toCharArray(); s sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int[] cnt = new int[n]; cnt new int[n] n for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        } {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        } if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            } s[i-1] == 'A' && s[i] == 'C' s[i-1] == 'A' s[i-1] s i-1 i 1 'A' s[i] == 'C' s[i] s i 'C' {
                cnt[i] = cnt[i-1] + 1;
            } cnt[i] = cnt[i-1] + 1 cnt[i] cnt i cnt[i-1] + 1 cnt[i-1] cnt i-1 i 1 1 {
                cnt[i] = cnt[i-1];
            } cnt[i] = cnt[i-1] cnt[i] cnt i cnt[i-1] cnt i-1 i 1 int[] ans = new int[q]; ans new int[q] q for (int i = 0; i < q; i++) {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            ans[i] = cnt[r] - cnt[l];
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            ans[i] = cnt[r] - cnt[l];
        } {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            ans[i] = cnt[r] - cnt[l];
        } int l = sc.nextInt()-1; l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int r = sc.nextInt()-1; r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 ans[i] = cnt[r] - cnt[l] ans[i] ans i cnt[r] - cnt[l] cnt[r] cnt r cnt[l] cnt l for (int i : ans)
            System.out.println(i); int i ans System.out.println(i); System.out.println(i) System.out.println System.out System System.out i 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();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

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

        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

        for (int i : ans)
            System.out.println(i);
    }
} Main
// インデックスまでのAC数を数えて、
// rまでのAC数からlまでのAC数を引くことで求める
// 参考 -> #4701870

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();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

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

        for (int i : ans)
            System.out.println(i);
    }
}
