import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    }
} Main public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int Q = scanner.nextInt(); Q scanner.nextInt() scanner.nextInt scanner String S = scanner.next(); S scanner.next() scanner.next scanner int a[] = new int[Q]; a new int[Q] Q int b[] = new int[Q]; b new int[Q] Q for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        } {
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        } a[i] =scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner b[i] =scanner.nextInt() b[i] b i scanner.nextInt() scanner.nextInt scanner int t[] = new int[N+1]; t new int[N+1] N+1 N 1 String find ="AC"; find "AC" for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        } {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        } if(i==0){t[i]=0;} i==0 i 0 {t[i]=0;} t[i]=0 t[i] t i 0 if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            } i>=1 && S.substring(i-1,i+1).equals(find) i>=1 i 1 S.substring(i-1,i+1).equals(find) S.substring(i-1,i+1).equals S.substring(i-1,i+1) S.substring S i-1 i 1 i+1 i 1 find {
                t[i] = 1;} t[i] = 1 t[i] t i 1 {t[i] = 0;
            } t[i] = 0 t[i] t i 0 int s[] = new int[N+1]; s new int[N+1] N+1 N 1 for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        } int i =0; int i =0; i 0 i<N i N i++ i++ i {
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        } {
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        } if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                } i==0 i 0 {s[i]=t[i];} s[i]=t[i] s[i] s i t[i] t i {
                s[i] = t[i] + s[i-1];
                } s[i] = t[i] + s[i-1] s[i] s i t[i] + s[i-1] t[i] t i s[i-1] s i-1 i 1 for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        } int i=0; int i=0; i 0 i<Q i Q i++ i++ i {
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        } {
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        } System.out.println(s[b[i]-1]-s[a[i]-1]) System.out.println System.out System System.out s[b[i]-1]-s[a[i]-1] s[b[i]-1] s b[i]-1 b[i] b i 1 s[a[i]-1] s a[i]-1 a[i] a i 1 String args[] args public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    }
} public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int a[] = new int[Q];
        int b[] = new int[Q];
        for(int i=0;i<Q;i++){
            a[i] =scanner.nextInt();
            b[i] =scanner.nextInt();
        }
        int t[] = new int[N+1];
        String find ="AC";
        for(int i=0;i<N;i++) {
            if(i==0){t[i]=0;}
            if(i>=1 && S.substring(i-1,i+1).equals(find)){
                t[i] = 1;}
            else{t[i] = 0;
            }
        }
        int s[] = new int[N+1];
        for(int i =0;i<N;i++){
            if(i==0){s[i]=t[i];}else{
                s[i] = t[i] + s[i-1];
                }
        }
        for(int i=0;i<Q;i++){
            System.out.println(s[b[i]-1]-s[a[i]-1]);
        }
    }
}