fun main(args: Array<String>) {
	val s = mutableMapOf<Char, String>()

	for (i in 0 until 3) {
		s['A' + i] = readLine()!!
	}

	var turn = 'A'

	while (s[turn]!! != "") {
		val pre = turn
		turn = s[turn]!![0].toUpperCase()

		s[pre] = s[pre]!!.slice(1..s[pre]!!.lastIndex)
	}

	println(turn)
}
