fun main(args: Array<String>) {
    var strA = readLine().orEmpty()
    var strB = readLine().orEmpty()
    var strC = readLine().orEmpty()
    val lengthAll = strA.length + strB.length + strC.length
    var player = 'a'
    var i = 0
    run loop@{
      while(i < lengthAll){
            if(player == 'a'){
                if(strA.isEmpty()){
                    return@loop
                }
                player = strA[0]
                strA = strA.drop(1)
            }else if(player == 'b'){
                if(strB.isEmpty()){
                    return@loop
                }
                player = strB[0]
                strB = strB.drop(1)
            }else if(player == 'c'){
                if(strC.isEmpty()){
                    return@loop
                }
                player = strC[0]
                strC = strC.drop(1)
            }
            i++
        }
    }


    println(player.toUpperCase())
}