import java.util.*;
import static java.lang.System.*;

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

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