import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    } 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 str = sc.next(); str sc.next() sc.next sc char[] c = str.toCharArray(); c str.toCharArray() str.toCharArray str int[] array = new int[n]; array new int[n] n for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        } {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        } if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            } c[i] == 'A' && c[i+1] == 'C' c[i] == 'A' c[i] c i 'A' c[i+1] == 'C' c[i+1] c i+1 i 1 'C' {
                array[i+1]++;
            } array[i+1]++ array[i+1] array i+1 i 1 int[] sum = new int[n+1]; sum new int[n+1] n+1 n 1 for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            sum[i] = sum[i-1] + array[i-1];
        } {
            sum[i] = sum[i-1] + array[i-1];
        } sum[i] = sum[i-1] + array[i-1] sum[i] sum i sum[i-1] + array[i-1] sum[i-1] sum i-1 i 1 array[i-1] array i-1 i 1 while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        } q-- > 0 q-- q 0 {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        } int i = sc.nextInt(); i sc.nextInt() sc.nextInt sc int j = sc.nextInt(); j sc.nextInt() sc.nextInt sc System.out.println(sum[j] - sum[i]) System.out.println System.out System System.out sum[j] - sum[i] sum[j] sum j sum[i] sum i String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] array = new int[n];
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'A' && c[i+1] == 'C') {
                array[i+1]++;
            }
        }
        
        int[] sum = new int[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + array[i-1];
        }
        // System.out.println(Arrays.toString(sum));
        
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            // System.out.println(i + " " + j);
            System.out.println(sum[j] - sum[i]);
        }
    }
}