'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))

	const t = {
		a: args[0][0].split(''),
		b: args[1][0].split(''),
		c: args[2][0].split('')
	}

	let next = 'a'

	while (true) {
		if (t[next].length === 0) break
		next = t[next].shift()
	}

	console.log(next.toUpperCase())
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
