import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = (1..3).map { sc.next().map { it - 'a' } }
    val idx = Array(3) {0}
    var now = 0
    while (true) {
        if (idx[now] == s[now].size) {
            println('A' + now)
            break
        }
        idx[now]++
        now = s[now][idx[now] - 1]
    }
}