def ball(c1, c2, b)
  case b
  when c1
    return c2
  when c2
    return c1
  else
    return b
  end
end

b = "A"

while line = gets
  cup1, cup2 = line.chomp.split(",")
  p b = ball(cup1, cup2, b)
end

puts b