process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////


function main() {
	var a = readLine();
	var b = readLine();
	var c = readLine();
	
	var turno = "a";
	while (true){
		var nextTurno;
		if (turno == "a"){
			nextTurno = a.substring(0,1);
			a = a.substring(1);
		} else if (turno == "b"){
			nextTurno = b.substring(0,1);
			b = b.substring(1);
		} else {
			nextTurno = c.substring(0,1);
			c = c.substring(1);
		}
		if (nextTurno.localeCompare("a") != 0 && 
		    nextTurno.localeCompare("b") != 0 &&
			nextTurno.localeCompare("c") != 0){
			break;
		}
		turno = nextTurno;
	}
	console.log(turno.toUpperCase());
	
    process.exit();
}