  // B - 3人でカードゲームイージー / Card Game for Three (ABC Edit) https://atcoder.jp/contests/abc045/tasks/abc045_b

  import io.Source

  object Main extends App {
    val xs = Source.stdin.getLines()
    val as = xs.next().toList
    val bs = xs.next().toList
    val cs = xs.next().toList

    println(solve('A', as, bs, cs))

    def solve(t: Char, as: List[Char], bs: List[Char], cs: List[Char]): String = {
      (t, as, bs, cs) match {
        case ('A', a :: ass, _, _) => solve(a.toUpper, ass, bs, cs)
        case ('B', _, b :: bss, _) => solve(b.toUpper, as, bss, cs)
        case ('C', _, _, c :: css) => solve(c.toUpper, as, bs, css)
        case (tt, _, _, _) => tt.toString
      }
    }
  }
