import java.io.*;
import  java.util.*;
import static java.lang.System.in;

public class Main{
    static int n,m;
    static long[] head,pos;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    }
} import java.io.*; io.* java import  java.util.*; util.* java import static java.lang.System.in; import static java.lang.System.in; import static java.lang.System.in; public class Main{
    static int n,m;
    static long[] head,pos;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    }
} Main static int n n m; m static long[] head head pos; pos public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc String src = " "+sc.next(); src " "+sc.next() " " sc.next() sc.next sc char[] s = src.toCharArray(); s src.toCharArray() src.toCharArray src int[] dp = new int[n+1]; dp new int[n+1] n+1 n 1 for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        } int i=2; int i=2; i 2 i<=n i n i++ i++ i {
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        } {
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        } if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1]; s[i]=='C'&&s[i-1]=='A' s[i]=='C' s[i] s i 'C' s[i-1]=='A' s[i-1] s i-1 i 1 'A' dp[i] = dp[i-2]+1 dp[i] dp i dp[i-2]+1 dp[i-2] dp i-2 i 2 1 dp[i] = dp[i-1] dp[i] dp i dp[i-1] dp i-1 i 1 PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        } {
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        } int le = sc.nextInt() le sc.nextInt() sc.nextInt sc ri = sc.nextInt(); ri sc.nextInt() sc.nextInt sc int ans = dp[ri]-dp[le-1]; ans dp[ri]-dp[le-1] dp[ri] dp ri dp[le-1] dp le-1 le 1 if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--; le>1&&s[le]=='C'&&s[le-1]=='A' le>1&&s[le]=='C'&&s[le-1]=='A' le>1 le 1 s[le]=='C' s[le] s le 'C' s[le-1]=='A' s[le-1] s le-1 le 1 'A' ans-- ans out.println(ans) out.println out ans out.flush() out.flush out String[] args args public class Main{
    static int n,m;
    static long[] head,pos;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    }
} public class Main{
    static int n,m;
    static long[] head,pos;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    }
} Main
import java.io.*;
import  java.util.*;
import static java.lang.System.in;

public class Main{
    static int n,m;
    static long[] head,pos;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    }
}
