function Main(input) {
	input = input.split("\n");
	input[0] = input[0].split("");
	input[1] = input[1].split("");
	input[2] = input[2].split("");
	var now = 0;
	var ans = "C";
  //console.log(input[now])
	while(input[now].length>0){
		switch(input[now][0]){
			case "a":
			input[now].shift();
			now = 0;
			break;
         	case "b":
			input[now].shift();
			now = 1;
			break;
			case "c":
			input[now].shift();
			now = 2;
			break;
		}
	}
	if(input[0].length==0){
		ans = "A"
	}else if(input[1].length==0){
		ans = "B"
	}
	console.log(ans)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
