import scala.io.StdIn

object Main extends App {

  val arr: Array[Array[Int]] = (0 until 3).map { _ =>
    StdIn.readLine().replace("a", "0").replace("b", "1").replace("c", "2").map(c => c.toString.toInt).toArray
  }.toArray

  //arr.foreach(e => println(e.toList))

  def loop(position: Array[Int], current: Int): Int = {
    if (position(current) + 1 == arr(current).length) current
    else {
      position(current) += 1
      loop(position, arr(current)(position(current)))
    }
  }

  val r = loop(Array(-1, -1, -1), 0)
  println(if (r == 0) "A" else if (r == 1) "B" else "C")

}
