sa = io.read()
sb = io.read()
sc = io.read()
local ta, tb, tc = 1, 1, 1
cur = "a"
while true do
  if cur == "a" then
    if #sa < ta then
      print("A") os.exit()
    end
    cur = sa:sub(ta, ta)
    ta = ta + 1
  elseif cur == "b" then
    if #sb < tb then
      print("B") os.exit()
    end
    cur = sb:sub(tb, tb)
    tb = tb + 1
  else
    if #sc < tc then
      print("C") os.exit()
    end
    cur = sc:sub(tc, tc)
    tc = tc + 1
  end
end
