fun main (args: Array<String>) {
  val (a, b, c) = (1..3).map { readLine()!! }.map(String::toMutableList)
  var card = a.removeAt(0)
  while (true) {
    when (card) {
      'a' -> {
        if (a.isEmpty()) {
          println('A')
          return
        }
        card = a.removeAt(0)
      }
      'b' -> {
        if (b.isEmpty()) {
          println('B')
          return
        }
        card = b.removeAt(0)
      }
      'c' -> {
        if (c.isEmpty()) {
          println('C')
          return
        }
        card = c.removeAt(0)
      }
    }
  }
}