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
        For i As Integer = 0 To Q - 1
            For j As Integer = 0 To r(i) - l(i)
                If Mid(S, l(i) + j, 1) = "A" Then
                    Ahurag = 1
                ElseIf Ahurag = 1 AndAlso Mid(S, l(i) + j, 1) = "C" Then
                    Ahurag = 0
                    counter += 1
                Else
                    Ahurag = 0
                End If
            Next
            Ahurag = 0
            Console.WriteLine(counter)
            counter = 0
        Next
        Console.ReadLine()
    End Sub

End Module