defmodule Main do
  def main do
    IO.stream(:stdio, :line)
    |> Enum.take(3)
    |> Enum.map(&String.trim/1)
    |> Enum.map(&String.split(&1, "", trim: true))
    |> process("a")
    |> IO.puts()
  end
  
  defp process([[], _, _], "a"), do: "A"
  defp process([_, [], _], "b"), do: "B"
  defp process([_, _, []], "c"), do: "C"
  defp process([[head | tail], b, c], "a"), do: process([tail, b, c], head)
  defp process([a, [head | tail], c], "b"), do: process([a, tail, c], head)
  defp process([a, b, [head | tail]], "c"), do: process([a, b, tail], head)
end