fun main(args:Array<String>) {
    val cards = (1..3).map { readLine()!!.map { it - 'a' }.toMutableList() }

    var current = 0
    while (cards.all { it.count() >= 0 }) {
        if(cards[current].isEmpty()) {
            println('A' + current)
            return
        }
        val num = cards[current][0]
        cards[current].removeAt(0)
        current = num
    }
}
