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

local discard="a"
while S["a"]~="" and S["b"]~="" and S["c"]~="" do
    discard=S[discard]:sub(1,1)
    S[discard]=S[discard]:sub(2,#S[discard])
    if S[discard]=="" then
        print(discard:upper())
        break
    end
end