import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
} import java.util.*; util.* java public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
} Main void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    } solve {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan String s = scan.next(); s scan.next() scan.next scan int[] l = new int[q]; l new int[q] q int[] r = new int[q]; r new int[q] q for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        } {
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        } l[i] = scan.nextInt() l[i] l i scan.nextInt() scan.nextInt scan r[i] = scan.nextInt() r[i] r i scan.nextInt() scan.nextInt scan int[] out = new int[n]; out new int[n] n for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        } {
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        } if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            } s.charAt(i) == 'C' && s.charAt(i - 1) == 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' {
                Arrays.fill(out, i, n, out[i - 1] + 1);
            } Arrays.fill(out, i, n, out[i - 1] + 1) Arrays.fill Arrays out i n out[i - 1] + 1 out[i - 1] out i - 1 i 1 1 for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        } {
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        } System.out.println(out[r[i] - 1] - out[l[i] - 1]) System.out.println System.out System System.out out[r[i] - 1] - out[l[i] - 1] out[r[i] - 1] out r[i] - 1 r[i] r i 1 out[l[i] - 1] out l[i] - 1 l[i] l i 1 public static void main(String[] args){
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
} public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
} Main
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        String s = scan.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int[] out = new int[n];
        for(int i = 1; i < n; i++){
            if(s.charAt(i) == 'C' && s.charAt(i - 1) == 'A'){
                Arrays.fill(out, i, n, out[i - 1] + 1);
            }
        }
        for(int i = 0; i < q; i++){
            System.out.println(out[r[i] - 1] - out[l[i] - 1]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}
