import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main(args: Array<String>) {
    val a = ArrayDeque<Char>()
    val b = ArrayDeque<Char>()
    val c = ArrayDeque<Char>()

    a.addAll(readString().map { it })
    b.addAll(readString().map { it })
    c.addAll(readString().map { it })

    var turn = a.first
    while (true) {
        when (turn) {
            'a' -> {
                if (a.isEmpty()) {
                    println("A")
                    return
                }
                turn = a.removeFirst()
            }
            'b' -> {
                if (b.isEmpty()) {
                    println("B")
                    return
                }
                turn = b.removeFirst()
            }
            'c' -> {
                if (c.isEmpty()) {
                    println("C")
                    return
                }
                turn = c.removeFirst()
            }
        }
    }
}

// read
fun readString() = readLine()!!