import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    }
} import java.util.*; util.* java public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    } 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 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] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        } {
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        } l[i] = sc.nextInt()-1 l[i] l i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 r[i] = sc.nextInt()-1 r[i] r i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int[] a = new int[N]; a new int[N] N for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        } {
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        } if(S.charAt(i) == 'A')
                a[i] = 1; S.charAt(i) == 'A' S.charAt(i) S.charAt S i 'A' a[i] = 1 a[i] a i 1 if(S.charAt(i) == 'C')
                a[i] = -1; S.charAt(i) == 'C' S.charAt(i) S.charAt S i 'C' a[i] = -1 a[i] a i -1 1 int[] dp = new int[N]; dp new int[N] N dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        } {
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        } if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i]; a[i] == 1 && a[i+1] == -1 a[i] == 1 a[i] a i 1 a[i+1] == -1 a[i+1] a i+1 i 1 -1 1 dp[i+1] = dp[i] + 1 dp[i+1] dp i+1 i 1 dp[i] + 1 dp[i] dp i 1 dp[i+1] = dp[i] dp[i+1] dp i+1 i 1 dp[i] dp i for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
            System.out.println(dp[r[i]] - dp[l[i]]);
        } {
            System.out.println(dp[r[i]] - dp[l[i]]);
        } System.out.println(dp[r[i]] - dp[l[i]]) System.out.println System.out System System.out dp[r[i]] - dp[l[i]] dp[r[i]] dp r[i] r i dp[l[i]] dp l[i] l i String args[] args public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    }
} public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    }
} Main
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt()-1;
            r[i] = sc.nextInt()-1;
        }
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'A')
                a[i] = 1;
            if(S.charAt(i) == 'C')
                a[i] = -1;
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 0; i < N-1; i++){
            if(a[i] == 1 && a[i+1] == -1)
                dp[i+1] = dp[i] + 1;
            else
                dp[i+1] = dp[i];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(dp[r[i]] - dp[l[i]]);
        }
    }
}
