import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val sA = sc.next
    val sB = sc.next
    val sC = sc.next

    val res = loop(sA,sB,sC, "a")

    println(res)
  }

  def loop(strA: String, strB: String, strC: String, player: String): String = {
//    println(s"(strA, strB, strC, player) = ${(strA, strB, strC, player)}")
    (strA, strB, strC, player) match{
      case ("", _, _, "a") => "A"
      case (_, "", _, "b") => "B"
      case (_, _, "", "c") => "C"

      case (stA, stB, stC, _) =>
        player match{
          case "a" => loop(stA.substring(1), stB, stC, stA.head.toString)
          case "b" => loop(stA, stB.substring(1), stC, stB.head.toString)
          case "c" => loop(stA, stB, stC.substring(1), stC.head.toString)
        }
    }
  }
}
