fun main(args: Array<String>) {
    val S = Array(3) { readLine()!!.toCharArray().toMutableList() }
    var turn = 0
    while (S[turn].isNotEmpty()) {
        turn = S[turn].removeAt(0).toInt() - 'a'.toInt()
    }
    println('A' + turn)
}

