import java.util.*;

public class Main {
    
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    }
} import java.util.*; util.* java public class Main {
    
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    }
} Main public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    } main {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    } 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 S = sc.next(); S sc.next() sc.next sc char[] buf = S.toCharArray(); buf S.toCharArray() S.toCharArray S int[] acCnt = new int[S.length()]; acCnt new int[S.length()] S.length() S.length S acCnt[0] = 0 acCnt[0] acCnt 0 0 int sumCnt = 0; sumCnt 0 for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        } int i = 1; int i = 1; i 1 i < S.length() i S.length() S.length S ++i ++i i {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        } {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        } if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            } (buf[i - 1] == 'A')  && (buf[i] == 'C') (buf[i - 1] == 'A') buf[i - 1] buf i - 1 i 1 'A' (buf[i] == 'C') buf[i] buf i 'C' {
                ++sumCnt;
            } ++sumCnt sumCnt acCnt[i] = sumCnt acCnt[i] acCnt i sumCnt for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        } int i = 0; int i = 0; i 0 i < Q i Q ++i ++i i {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        } {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        } int l = sc.nextInt() - 1; l sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int r = sc.nextInt() - 1; r sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int cnt = acCnt[r] - acCnt[l]; cnt acCnt[r] - acCnt[l] acCnt[r] acCnt r acCnt[l] acCnt l System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    }
} public class Main {
    
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    }
} Main
import java.util.*;

public class Main {
    
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    }
}
