Option Strict On
Module Module1

    Sub Main()
        Dim z() As String = Split(Console.ReadLine())
        Dim N As Integer = Convert.ToInt32(z(0))
        Dim Q As Integer = Convert.ToInt32(z(1))
        Dim S As String = Console.ReadLine()
        Dim l(Q - 1) As Integer
        Dim r(Q - 1) As Integer
        For i As Integer = 0 To Q - 1
            z = Split(Console.ReadLine())
            l(i) = Convert.ToInt32(z(0))
            r(i) = Convert.ToInt32(z(1))
        Next
        '        For Each t In l
        'Console.WriteLine(t)
        'Next
        'For Each t In r
        'Console.WriteLine(t)
        'Next
        Dim Ahurag As Integer = 0
        Dim counter As Integer = 0
        Dim at(N - 1) As Integer
        For i As Integer = 0 To N - 1
            If Mid(S, i + 1, 1) = "A" Then
                Ahurag = 1
            ElseIf Ahurag = 1 AndAlso Mid(S, i + 1, 1) = "C" Then
                Ahurag = 0
                counter += 1

            Else
                Ahurag = 0
            End If
            at(i) += counter
        Next
        Dim answer As Integer = 0
        For i As Integer = 0 To Q - 1
            answer = at(r(i) - 1) - at(l(i) - 1)
            Console.WriteLine(answer)
        Next
        Console.ReadLine()
    End Sub

End Module