import java.util.*

fun main(args: Array<String>) {
//    val sc = Scanner(System.`in`)

    val S = Array(3) { ArrayDeque(readLine()!!.toCharArray().toList()) }

    var current = S[0].poll()

    while(true) {
        current = when (current) {
            'a' -> {
                if (S[0].isEmpty()) {
                    println("A")
                    return
                }
                S[0].poll()
            }
            'b' -> {
                if (S[1].isEmpty()) {
                    println("B")
                    return
                }
                S[1].poll()
            }
            'c' -> {
                if (S[2].isEmpty()) {
                    println("C")
                    return
                }
                S[2].poll()
            }
            else -> throw IllegalStateException("")
        }
    }

}