fun main(args: Array<String>) = println(run {
    val s = (1..3).map { readLine()!! }
    val i = intArrayOf(0,0,0)

    var t = 0
    while (true) {
        if(s[t].lastIndex < i[t]) return@run 'A'+t
        t = s[t][i[t]++]-'a'
    }

})