import scala.io.StdIn

object Main extends App {

  val arr = (0 until 3).map(_ => StdIn.readLine().replace("a", "0").replace("b", "1").replace("c", "2").map(c => c.toString.toInt)).toArray

  var card = arr(0)(0)
  var ai = 1
  var bi = 0
  var ci = 0
  arr.foreach(e => println(e.toList))
  
  while (ai + 1 < arr(0).length && bi + 1 < arr(1).length && ci + 1 < arr(2).length) {
    if (ai == card){
      card = arr(card)(ai)
      ai += 1
    } 
    else if (bi == card){
      card = arr(card)(bi)
      bi += 1
    } 
    else {
      card = arr(card)(ci)
      ci += 1
    }
  }

  println(if(card == 0) "A" else if(card == 1) "B" else "C")

}
