"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = arg[0].split("");
    const B = arg[1].split("");
    const C = arg[2].split("");
    
    let now = "a";
    
    while(true) {
        // console.log("now:" + now);
        // console.log("A:" + A);
        // console.log("B:" + B);
        // console.log("C:" + C);
        // console.log("--------")
        
        if(now === "a") {
            if(A.length === 0) break;
            let temp = A.shift();

            now = temp;
        } else if(now === "b") {
            if(B.length === 0) break;
            let temp = B.shift();
            
            now = temp;
        } else {
            if(C.length === 0) break;
            let temp = C.shift();
            
            now = temp;
        }
    }
    
    let answer;
    
    if(now === "a") {
        answer = "A";
    } else if(now === "b") {
        answer = "B";
    } else {
        answer = "C";
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));