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();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
} 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();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
} 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();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    } 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 String[] strAry = new String[n]; strAry new String[n] n for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            strAry[i] = String.valueOf(str.charAt(i));
        } {
            strAry[i] = String.valueOf(str.charAt(i));
        } strAry[i] = String.valueOf(str.charAt(i)) strAry[i] strAry i String.valueOf(str.charAt(i)) String.valueOf String str.charAt(i) str.charAt str i int[] cumsum = new int[n + 1]; cumsum new int[n + 1] n + 1 n 1 for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        } {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        } if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            } str.charAt(i - 1) == 'A' && str.charAt(i) == 'C' str.charAt(i - 1) == 'A' str.charAt(i - 1) str.charAt str i - 1 i 1 'A' str.charAt(i) == 'C' str.charAt(i) str.charAt str i 'C' {
                cumsum[i + 1] = cumsum[i] + 1;
            } cumsum[i + 1] = cumsum[i] + 1 cumsum[i + 1] cumsum i + 1 i 1 cumsum[i] + 1 cumsum[i] cumsum i 1 {
                cumsum[i + 1] = cumsum[i];
            } cumsum[i + 1] = cumsum[i] cumsum[i + 1] cumsum i + 1 i 1 cumsum[i] cumsum i while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        } q-- > 0 q-- q 0 {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        } int start = sc.nextInt(); start sc.nextInt() sc.nextInt sc int end = sc.nextInt(); end sc.nextInt() sc.nextInt sc int count = cumsum[end] - cumsum[start]; count cumsum[end] - cumsum[start] cumsum[end] cumsum end cumsum[start] cumsum start System.out.println(count) System.out.println System.out System System.out count 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();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
} 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();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
} 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();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
}