Which sentence has the correct pronoun and antecedent agreement

Because the brothers were tired, he forgot to shut the gate and the dogs ran out

The dogs wagged their tails.

When the teachers arrived at school, she saw the students writing with chalk

The cat is sitting in the windowsill, and then is basking in the sun

The dogs wagged their tails.