fun main(args: Array<String>) {
    val abc = (1..3).map { readLine()!!.map { it - 'a' } }
    val cnt = Array(3) { 0 }
    var turn = 0
    while (abc[turn].getOrNull(cnt[turn]) != null) {
        val nextTurn = abc[turn].get(cnt[turn])
        cnt[turn]++
        turn = nextTurn
    }
    println('A' + turn)
}
