function Main(input) {
	input = input.trim().split("\n");
  var list = {
  	"A" : input[0].split(""),
  	"B" : input[1].split(""),
  	"C" : input[2].split("")
  }
  var turn = "A";
  while(true){
    if(list[turn].length == 0){
       break;
    }else{
       turn = list[turn].shift().toUpperCase();
    }
  }
  console.log(turn);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
