object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c = sc.next()

  def solve(a: String, b: String, c: String, turn: Char): String = {
    turn match {
      case 'a' =>
        if (a.isEmpty) {
          "A"
        } else {
          solve(a.tail, b, c, a.head)
        }
      case 'b' =>
        if (b.isEmpty) {
          "B"
        } else {
          solve(a, b.tail, c, b.head)
        }
      case 'c' =>
        if (c.isEmpty) {
          "C"
        } else {
          solve(a, b, c.tail, c.head)
        }
    }
  }

  println(solve(a, b, c, 'a'))
}
