Detailed Instructions: Given a premise, an initial context, an original ending, and a counterfactual context, the task is to generate a new story ending aligned with the counterfactual context and as close to the original ending as possible. Each instance consists of a five-sentence story. The premise is the first sentence of a story, and the second sentence, which is the initial context, provides more information about the story's context and the story's general plot. The original ending is the last three sentences of the story. Also, a counterfactual context is a slight modification to the initial context. You should write a new story ending that edits the original story ending as little as possible to regain coherence with the counterfactual context. To sum up, you should write the last three sentences of a story based on the premise(first sentence) and the counterfactual context(second sentence) of the story.
Q: Premise: Jim really wanted to show his dog at the annual dog show. 
 Initial Context: But his dog was very bad-mannered and always ran away. 
 Original Ending: Bob took his dog to obedience classes for four weeks. Bob's dog learned how to stay when Bob commanded it. Bob and his dog entered the contest and won second place. 
 Counterfactual Context: His dog was the best when he took obedience class last year.
A:
Bob had taken his dog to obedience classes for four weeks. Bob's dog learned how to stay when Bob commanded it. Bob and his dog entered the contest and won second place. 