
import java.util.Scanner;

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

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        String s = scanner.next();
        int [] l = new int[q];
        int [] r = new int[q];
        for (int i = 0; i < q; ++i) {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int [] sum = new int[n];
        for (int i = 0; i  + 1 < s.length(); i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                sum[i + 1]++;
            }
            sum[i + 1] += sum[i];
        }

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    }

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

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        String s = scanner.next();
        int [] l = new int[q];
        int [] r = new int[q];
        for (int i = 0; i < q; ++i) {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int [] sum = new int[n];
        for (int i = 0; i  + 1 < s.length(); i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                sum[i + 1]++;
            }
            sum[i + 1] += sum[i];
        }

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

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

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    }

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

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    }

} Main

import java.util.Scanner;

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

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    }

}
