import java.util.*

fun main(args: Array<String>) {
    abc045b()
}

fun abc045b() {
    val abcList = (1..3).map { readLine()!!.toCharArray().map { it.toInt() - 97 } }
        .map { ArrayDeque(it) }

    var nextTurn = 0
    while (true) {
        nextTurn = abcList[nextTurn].pollFirst() ?: return println((nextTurn + 65).toChar())
    }
}
