import scala.io.StdIn
object Main {
  def main(args: Array[String]): Unit = {
    val a = StdIn.readLine()
    val b = StdIn.readLine()
    val c = StdIn.readLine()

    val env = Map('a' -> a.toList, 'b' -> b.toList, 'c' -> c.toList)

    @scala.annotation.tailrec
    def solve(e: Map[Char, List[Char]], c: Char): Char = e(c) match {
      case x :: xs => solve(e + (c -> xs), x)
      case Nil => c
    }

    println(solve(env, 'a').toString.toUpperCase())
  }
}
