import 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 s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    } 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 List<Integer> l = new ArrayList<>(); l new ArrayList<>() List<Integer> r = new ArrayList<>(); r new ArrayList<>() for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        } {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        } l.add(sc.nextInt()) l.add l sc.nextInt() sc.nextInt sc r.add(sc.nextInt()) r.add r sc.nextInt() sc.nextInt sc int[] sum = new int[n]; sum new int[n] n sum[0] = 0 sum[0] sum 0 0 for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        } {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        } if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            } s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' {
                sum[i] = sum[i - 1] + 1;
                continue;
            } sum[i] = sum[i - 1] + 1 sum[i] sum i sum[i - 1] + 1 sum[i - 1] sum i - 1 i 1 1 continue; sum[i] = sum[i - 1] sum[i] sum i sum[i - 1] sum i - 1 i 1 for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        } {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        } int left = l.get(i) - 1; left l.get(i) - 1 l.get(i) l.get l i 1 int right = r.get(i) - 1; right r.get(i) - 1 r.get(i) r.get r i 1 int ans = sum[right] - sum[left]; ans sum[right] - sum[left] sum[right] sum right sum[left] sum left System.out.println(ans) System.out.println System.out System System.out ans 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 s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    }
} Main
import 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 s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    }
}
