program atcoder
implicit none
character(len=100) :: a, b, c
character :: t

read(*,*) a, b, c

t = a(1:1)
a = a(2:100)

do
	if (t == 'a') then
    	t = a(1:1)
        a = a(2:100)
	else if (t == 'b') then
    	t = a(1:1)
        b = b(2:100)
	else
    	t = a(1:1)
        c = c(2:100)
	end if
    if (trim(a) == '')then
    	write(*,'(a)') 'A'
        stop
    else if (trim(b) == '')then
    	write(*,'(a)') 'B'
        stop
    else if (trim(c) == '')then
    	write(*,'(a)') 'C'
        stop
    end if
end do

end program atcoder