import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    }
} Main public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    } main {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    } Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = std.nextInt(); n std.nextInt() std.nextInt std int q = std.nextInt(); q std.nextInt() std.nextInt std String s = std.next(); s std.next() std.next std int[] l = new int[q]; l new int[q] q int[] r = new int[q]; r new int[q] q for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        } {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        } l[i] = std.nextInt() - 1 l[i] l i std.nextInt() - 1 std.nextInt() std.nextInt std 1 r[i] = std.nextInt() - 1 r[i] r i std.nextInt() - 1 std.nextInt() std.nextInt std 1 String ac = "AC"; ac "AC" int[] sum = new int[n]; sum new int[n] n for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        } int i = 1; int i = 1; i 1 i < s.length() i s.length() s.length s i++ i++ i {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        } {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        } char current = s.charAt(i); current s.charAt(i) s.charAt s i char before = s.charAt(i - 1); before s.charAt(i - 1) s.charAt s i - 1 i 1 if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            } before == 'A' && current == 'C' before == 'A' before 'A' current == 'C' current 'C' {
                sum[i] = sum[i - 1] + 1;
            } sum[i] = sum[i - 1] + 1 sum[i] sum i sum[i - 1] + 1 sum[i - 1] sum i - 1 i 1 1 {
                sum[i] = sum[i - 1];
            } 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 count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        } {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        } int count = sum[r[i]] - sum[l[i]]; count sum[r[i]] - sum[l[i]] sum[r[i]] sum r[i] r i sum[l[i]] sum l[i] l i System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    }
}
