import std.stdio;
import std.regex;

void main(){
	//auto io = new IO();
	char[][char] card;
	card['a'] = str();//io.rect!char()[0];
	card['b'] = str();
	card['c'] = str();
	
	char[char] ptr;
	ptr['a']=ptr['b']=ptr['c']=0;
	//= ["a":0,"b":0,"c":0];
	char target = 'a';
	
	foreach( i ; 0..100*100*100+10 ){
		auto now = ptr[target];
		if ( now >= card[target].length  ){
			target.toUpper().writeln();
			return;
		}
		
		ptr[target]++;
		target = card[target][now];
	}
}

char[] str(){
	char[] ret;
	foreach( elm ; readln().chomp().split() ){
		//ret ~= elm.to!char();
		ret ~= elm;
	}
	return ret;
}


import std.stdio,std.conv,std.string,std.uni;
import std.algorithm,std.array,std.math;
import std.bigint;