import java.util.*

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

fun abc045b() {
    val abcList = (1..3).map {
        readLine()!!.toCharArray().map {
            when (it) {
                'a' -> 0
                'b' -> 1
                else -> 2
            }
        }
    }.map { ArrayDeque(it) }

    var nextTurn = 0
    while (true) {
        nextTurn = abcList[nextTurn].pollFirst() ?: return println(
            when (nextTurn) {
                0 -> "A"
                1 -> "B"
                else -> "C"
            }
        )

    }
}
