program main
	character*100 sa,sb,sc
    integer::a=1,b=1,c=1
    integer::t=1,i=0
    read *,sa
    read *,sb
    read *,sc
    do
    	if (t==1) then
        	i=1
          	if(a==len_trim(sa)+1) then
              	print *, 'A'
                exit
            else if(sa(a:a)=='a') then
               	a=a+1
            else if(sa(a:a)=='b') then
              	a=a+1
                t=2
            else !then
            	a=a+1
                t=3
            end if
        else if(t==2) then
            if(b==len_trim(sb)+1) then
               	print *, 'B'
                stop
            else if(sb(b:b)=='a') then
               	b=b+1
                t=1
            else if(sb(b:b)=='b') then
              	b=b+1
            else! then
             	b=b+1
                t=3
            end if
		else if(t==3) then
            if(c==len_trim(sc)+1) then
               	print *,'C'
                stop
            else if(sc(c:c)=='a') then
              	c=c+1
                t=1
            else if(sc(c:c)=='b') then
              	c=c+1
                t=2
            else! then
              	c=c+1
            end if
        end if
   	end do
end program main