import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    }
} import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util import java.util.HashSet; HashSet java.util public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    } main {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    } 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 [] ans = new int [Q]; ans new int [Q] Q int [] ref = new int [N]; ref new int [N] N int sum = 0; sum 0 for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        } {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        } if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            } S.charAt(i) == 'A' && S.charAt(i+1) == 'C' S.charAt(i) == 'A' S.charAt(i) S.charAt S i 'A' S.charAt(i+1) == 'C' S.charAt(i+1) S.charAt S i+1 i 1 'C' {
                sum++;
                ref[i+1] += sum;
            } sum++ sum ref[i+1] += sum ref[i+1] ref i+1 i 1 sum {
                ref[i+1] += sum;
            } ref[i+1] += sum ref[i+1] ref i+1 i 1 sum for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        } {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        } int start = sc.nextInt() - 1; start sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int fin = sc.nextInt() - 1; fin sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 ans[i] = ref[fin] - ref[start] ans[i] ans i ref[fin] - ref[start] ref[fin] ref fin ref[start] ref start for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            System.out.println(ans[i]);
        } {
            System.out.println(ans[i]);
        } System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i String[] args args public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    }
} public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    }
} Main
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int [] ans = new int [Q];
        int [] ref = new int [N];
        int sum = 0;
        for (int i = 0; i < N-1; i++) {
            if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                sum++;
                ref[i+1] += sum;
            } else {
                ref[i+1] += sum;
            }
        }
        for (int i = 0; i < Q; i++) {
            int start = sc.nextInt() - 1;
            int fin = sc.nextInt() - 1;
            ans[i] = ref[fin] - ref[start];
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    }
}
