fun main(args: Array<String>) = yorukatsu22c()

fun yorukatsu22c() {
    val list = (1..3).map { readLine()!!.map { it - 'a' } }.toMutableList()

    var turn = 0

    while (true) {
        val next = if (list[turn].isEmpty())
            return println((turn + 'A'.toInt()).toChar()) else list[turn].first()
        list[turn] = list[turn].drop(1)
        turn = next
    }
}
