Option Strict On
Imports System.Console
Imports System.Collections.Generic

Module Program
    Const n As Integer = 3

    Sub Main()
        Dim s As New Dictionary(Of Integer, String)

        For i As Integer = 0 To n - 1
            s(Asc("A") + i) = NextString()
        Next

        Dim turn As Integer = Asc("A")

        Do While s(turn) <> ""
            Dim pre As Integer = turn
            turn = Asc(StrConv(s(turn)(0), vbUpperCase))
            s(pre) = Mid(s(pre), 2)
        Loop

        WriteLine(Chr(turn))
    End Sub

    Function NextString() As String
        Dim result As New List(Of String)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return String.Join("", result)
    End Function

End Module
