local S={}
S["a"]=io.read()
S["b"]=io.read()
S["c"]=io.read()

local discard="a"
while true do
    if S[discard]=="" then
        print(discard:upper())
        break
    end
    discard,S[discard]=S[discard]:sub(1,1),S[discard]:sub(2)
end