function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var aa = input[0];
    var bb = input[1];
    var cc = input[2];
    var count = [0,0,0];
    var limit = [aa.length,bb.length,cc.length];
    var current = "a";
    var tes = 0
    while(1){
        if(current==="a"){
            if(count[0]>=limit[0]){
                console.log("A");
                break;
            }
            current = aa[count[0]];
            count[0]++;
        } else if (current==="b"){
            if(count[1]>=limit[1]){
                console.log("B");
                break;
            }
            current = bb[count[1]];
            count[1]++;
        } else if (current==="c"){
            if(count[2]>=limit[2]){
                console.log("C");
                break;
            }
            current = cc[count[2]];
            count[2]++;
        }

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