A. "Beavers, by the way," said Melinda, "are herbivores."Is correct. Because it has properly used the quotation marks and the comma.
Why the rest is incorrect is because a quotation mark is when you quote what someone has said.
Use B as an example : "I'm home, Brian said." - The quotation marks have to be at the end of 'home,' because the person who is actually saying it wouldn't include 'Brian said' in their speech.