import scala.io.Source

object Main {

  def parse(xs: Seq[String]) =
    (xs(0).toSeq, xs(1).toSeq, xs(2).toSeq)

  def play(x: Char, as: Seq[Char], bs: Seq[Char], cs: Seq[Char]): Char =
    x match {
      case 'a' =>
        as match {
          case Nil => x
          case x1 +: rest => play(x1, rest, bs, cs)
        }
      case 'b' =>
        bs match {
          case Nil => x
          case x1 +: rest => play(x1, as, rest, cs)
        }
      case 'c' =>
        cs match {
          case Nil => x
          case x1 +: rest => play(x1, as, bs, rest)
        }
    }

  def main(args: Array[String]) {
    val (a, b, c) = parse(Source.stdin.getLines.toSeq)
    val winner = play('a', a, b, c)
    println(winner.toString.toUpperCase)
  }

}
