import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String s = in.next();
        int c[] = new int[n];

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

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

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

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

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

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

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

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

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

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

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String s = in.next();
        int c[] = new int[n];

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

        for (int i = 0; i < q; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;
            System.out.println(c[r] - c[l]);
        }
    }
}