import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val a = sc.next()
  val b = sc.next()
  val c = sc.next()


  var ai = 0
  var bi = 0
  var ci = 0
  
  var now = 'a'
  var last = "A"
  while (ai <= a.length && bi <= b.length && ci <= c.length) {
    if (now == 'a') {
      last = "A"
      if (ai == a.length) break
      now = a[ai]
      ai++
    } else if (now == 'b') {
      last = "B"
      if (bi == b.length) break
      now = b[bi]
      bi++
    } else if (now == 'c') {
      last = "C"
      if (ci == c.length) break
      now = c[ci]
      ci++
    }
  }

  println(last)


}
