fun next(player: Char, cards: StringBuilder): Char {
    if (cards.isEmpty()) {
        return player
    }
    val next = cards[0]
    cards.deleteCharAt(0)
    return next
}

fun main(args: Array<String>) {
    val sa = StringBuilder(readLine())
    val sb = StringBuilder(readLine())
    val sc = StringBuilder(readLine())
    var current = 'a'
    loop@ while (true) {
        when (current) {
            'a' -> current = next('A', sa)
            'b' -> current = next('B', sb)
            'c' -> current = next('C', sc)
            else -> break@loop
        }
    }
    println(current)
}
