import java.util.Scanner;

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();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        }
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        }
    }
} import java.util.Scanner; Scanner java.util 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();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        }
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        }
    }
} 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();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        }
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        }
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        }
    } 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 int[] count = new int[N]; count new int[N] N for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        } {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        } if (i == 0) {
                count[i] = 0;
                continue;
            } i == 0 i 0 {
                count[i] = 0;
                continue;
            } count[i] = 0 count[i] count i 0 continue; int e = 0; e 0 if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            } 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' {
                e++;
            } e++ e count[i] = count[i-1] + e count[i] count i count[i-1] + e count[i-1] count i-1 i 1 e for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(count[r - 1] - count[l - 1]) System.out.println System.out System System.out count[r - 1] - count[l - 1] count[r - 1] count r - 1 r 1 count[l - 1] count l - 1 l 1 String[] args args
import java.util.Scanner;

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();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        }
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        }
    }
}