import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;

void main(){
    auto as=readln.chomp.array;
    auto bs=readln.chomp.array;
    auto cs=readln.chomp.array;

    auto turn=0;
    while(true){
        final switch(turn){
            case 0:
                if(!as.any){
                    writeln("A");return;
                }
                turn=int(as[0]-'a');
                as=as[1..$];
                break;
            case 1:
                if(!bs.any){
                    writeln("B");return;
                }
                turn=int(bs[0]-'a');
                bs=bs[1..$];
                break;
            case 2:
                if(!cs.any){
                    writeln("C");return;
                }
                turn=int(cs[0]-'a');
                cs=cs[1..$];
                break;
        }
    }
}
