import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val a = read()
    val b = read()
    val c = read()
    val card = arrayOf(a,b,c)
    var num = intArrayOf(0,0,0)
    val s = "ABC"
    var win = 0
    var turn = 0
    while(true){
        if(num[turn] == card[turn].length){
            win = turn
            break
        }
        var next = 0
        if(card[turn][num[turn]] == 'a'){
            next = 0
        }
        else if(card[turn][num[turn]] == 'b'){
            next = 1
        }
        else{
            next = 2
        }
        num[turn]++
        turn = next
    }
    println(s[win])
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}