import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    }
} import java.util.*; util.* java import java.util.stream.*; stream.* java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    } main {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt() N in.nextInt() in.nextInt in Q = in.nextInt(); Q in.nextInt() in.nextInt in in.nextLine() in.nextLine in char[] S = in.nextLine().toCharArray(); S in.nextLine().toCharArray() in.nextLine().toCharArray in.nextLine() in.nextLine in 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] = in.nextInt();
            r[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        } {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        } l[i] = in.nextInt() l[i] l i in.nextInt() in.nextInt in r[i] = in.nextInt() r[i] r i in.nextInt() in.nextInt in int[] ac = new int[N + 1]; ac new int[N + 1] N + 1 N 1 for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        } {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        } ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0) ac[i] ac i ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0) ac[i - 1] ac i - 1 i 1 (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0) S[i - 1] == 'A' && S[i] == 'C' S[i - 1] == 'A' S[i - 1] S i - 1 i 1 'A' S[i] == 'C' S[i] S i 'C' 1 0 for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        } {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        } System.out.println(ac[r[i] - 1] - ac[l[i] - 1]) System.out.println System.out System System.out ac[r[i] - 1] - ac[l[i] - 1] ac[r[i] - 1] ac r[i] - 1 r[i] r i 1 ac[l[i] - 1] ac l[i] - 1 l[i] l i 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    }
} Main
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    }
}