import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    }
} import java.util.*; util.* java import java.util.Collections; Collections java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int Q = Integer.parseInt(sc.next()); Q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc String S = sc.next(); S sc.next() sc.next sc String[] sp = S.split(""); sp S.split("") S.split S "" int[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q int[] sum = new int[sp.length]; sum new int[sp.length] sp.length sp sp.length sum[0] = 0 sum[0] sum 0 0 int count = 0; count 0 for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        } {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        } if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            } sp[i-1].equals("A") && sp[i].equals("C") sp[i-1].equals("A") sp[i-1].equals sp[i-1] sp i-1 i 1 "A" sp[i].equals("C") sp[i].equals sp[i] sp i "C" {
                count++;
                sum[i-1] = count;
            } count++ count sum[i-1] = count sum[i-1] sum i-1 i 1 count sum[i] = count sum[i] sum i count int last = 0; last 0 int first = 0; first 0 int ans = 0; ans 0 for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        } {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        } first = Integer.parseInt(sc.next()) first Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc last = Integer.parseInt(sc.next()) last Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc first-- first last-- last if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            } sum[last] == 0 sum[last] sum last 0 {
                System.out.println(0);
            } System.out.println(0) System.out.println System.out System System.out 0 if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            } first == 0 first 0 { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            } if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                } sum[last] == sum[last-1] sum[last] sum last sum[last-1] sum last-1 last 1 {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                } if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    } sum[first] == 0 sum[first] sum first 0 {
                        System.out.println(sum[last]);
                    } System.out.println(sum[last]) System.out.println System.out System System.out sum[last] sum last {
                        System.out.println(sum[last] - sum[first] + 1);
                    } System.out.println(sum[last] - sum[first] + 1) System.out.println System.out System System.out sum[last] - sum[first] + 1 sum[last] - sum[first] sum[last] sum last sum[first] sum first 1 {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                } if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    } sum[first] == 0 sum[first] sum first 0 {
                        System.out.println(sum[last] - 1);
                    } System.out.println(sum[last] - 1) System.out.println System.out System System.out sum[last] - 1 sum[last] sum last 1 {
                        System.out.println(sum[last] - sum[first]);
                    } System.out.println(sum[last] - sum[first]) System.out.println System.out System System.out sum[last] - sum[first] sum[last] sum last sum[first] sum first if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            } last - first == 1 last - first last first 1 {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            } if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                } sum[first] == sum[first-1] sum[first] sum first sum[first-1] sum first-1 first 1 {
                    System.out.println(0);
                } System.out.println(0) System.out.println System.out System System.out 0 {
                    System.out.println(1);
                } System.out.println(1) System.out.println System.out System System.out 1 {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            } if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                } sum[first] != sum[first-1] && sum[last] == sum[last-1] sum[first] != sum[first-1] sum[first] sum first sum[first-1] sum first-1 first 1 sum[last] == sum[last-1] sum[last] sum last sum[last-1] sum last-1 last 1 {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                } System.out.println(sum[last] - sum[first] + 1) System.out.println System.out System System.out sum[last] - sum[first] + 1 sum[last] - sum[first] sum[last] sum last sum[first] sum first 1 if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                } sum[first] != sum[first-1] && sum[last] != sum[last-1] sum[first] != sum[first-1] sum[first] sum first sum[first-1] sum first-1 first 1 sum[last] != sum[last-1] sum[last] sum last sum[last-1] sum last-1 last 1 {
                    System.out.println(sum[last] - sum[first]);
                //➂
                } System.out.println(sum[last] - sum[first]) System.out.println System.out System System.out sum[last] - sum[first] sum[last] sum last sum[first] sum first if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                } sum[first] == sum[first-1] && sum[last] == sum[last-1] sum[first] == sum[first-1] sum[first] sum first sum[first-1] sum first-1 first 1 sum[last] == sum[last-1] sum[last] sum last sum[last-1] sum last-1 last 1 {
                    System.out.println(sum[last] - sum[first]);
                //④
                } System.out.println(sum[last] - sum[first]) System.out.println System.out System System.out sum[last] - sum[first] sum[last] sum last sum[first] sum first {
                    System.out.println(sum[last] - sum[first] - 1);
                } System.out.println(sum[last] - sum[first] - 1) System.out.println System.out System System.out sum[last] - sum[first] - 1 sum[last] - sum[first] - 1 sum[last] sum last sum[first] sum first 1 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    }
} Main
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    }
}