import io.{StdIn => in}

object Main extends App {
  val s = Iterator.continually(in.readLine).take(3).map(_ + ".").toArray
  val p = Array.ofDim[Int](3)
  val map = Map('a' -> 0, 'b' -> 1, 'c' -> 2)
  def f(n:Int):Int = {
    if(s(n).charAt(p(n)) == '.') n
    else {
      val ch = s(n).charAt(p(n))
      p(n) += 1
      f(map(ch))
    }
  }

  val ans = f(0) match {
    case 0 => "A"
    case 1 => "B"
    case 2 => "C"
    case _ => "error"
  }
  println(ans)
}