import 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();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    }
} import java.util.*; util.* java 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();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    }
} 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();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    } 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 int[] l = new int[Q]; l new int[Q] Q int[] r = new int[Q]; r new int[Q] Q int dp[] = new int[N]; dp new int[N] N String[] sp = S.split(""); sp S.split("") S.split S "" int count = 0; count 0 for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = 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++;
            }
            dp[i-1] = count;
        } {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        } if(sp[i-1].equals("A") && sp[i].equals("C")) {
                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++;
            } count++ count dp[i-1] = count dp[i-1] dp i-1 i 1 count dp[N-1] = count dp[N-1] dp N-1 N 1 count int ans = 0; ans 0 for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        } {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        } l[i] = Integer.parseInt(sc.next())-1 l[i] l i Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 r[i] = Integer.parseInt(sc.next())-1 r[i] r i Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            } l[i] == 0 l[i] l i 0 {
                ans = dp[r[i]-1];
            } ans = dp[r[i]-1] ans dp[r[i]-1] dp r[i]-1 r[i] r i 1 {
                ans = dp[r[i]-1] - dp[l[i]-1];
            } ans = dp[r[i]-1] - dp[l[i]-1] ans dp[r[i]-1] - dp[l[i]-1] dp[r[i]-1] dp r[i]-1 r[i] r i 1 dp[l[i]-1] dp l[i]-1 l[i] l i 1 System.out.println(ans) System.out.println System.out System System.out ans 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();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    }
} 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();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    }
} Main
import 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();
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int dp[] = new int[N];
        String[] sp = S.split("");
        
        int count = 0;
        for(int i=1; i<N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
            }
            dp[i-1] = count;
        }
        dp[N-1] = count;
        int ans = 0;
        
        for(int i=0; i<Q; i++) {
            l[i] = Integer.parseInt(sc.next())-1;
            r[i] = Integer.parseInt(sc.next())-1;
            if(l[i] == 0) {
                ans = dp[r[i]-1];
            }else {
                ans = dp[r[i]-1] - dp[l[i]-1];
            }
            System.out.println(ans);
        }
    }
}