fun main(args: Array<String>) {
    val sa = readLine()!!.toCharArray().map { ij -> ij.toString() }
    val sb = readLine()!!.toCharArray().map { ij -> ij.toString() }
    val sc = readLine()!!.toCharArray().map { ij -> ij.toString() }
    
    println(game("a", sa, sb, sc).toUpperCase())
}

fun game(now: String, sa: List<String>, sb: List<String>, sc: List<String>): String {
    when (now) {
        "a" -> {
            return if (sa.isEmpty()) {
                "a"
            } else {
                game(sa[0], sa.drop(1), sb, sc)
            }
        }
        "b" -> {
            return if (sb.isEmpty()) {
                "b"
            } else {
                game(sb[0], sa, sb.drop(1), sc)
            }
        }
        "c" -> {
            return if (sc.isEmpty()) {
                "c"
            } else {
                game(sc[0], sa, sb, sc.drop(1))
            }
        }
        else -> {
            return "error"
        }
    }
}