fun main(arr: Array<String>) {
    println(solve().toString().toUpperCase())
}

fun solve():Char {
    val dic = mutableMapOf('a' to readLine()!!)
    dic['b'] = readLine()!!
    dic['c'] = readLine()!!
    var current = 'a'
    for(i in (1..400)) {
        if(dic[current]!!.isEmpty()) {
            return current
        }
        val next = dic[current]!!.first()
        dic[current] = dic[current]!!.drop(1)
        current = next
    }
    return current
}