Either way is correct.
but in mexico it usually goes before and in spain it's usually attached to the end.
Answer:
el heroe subio a la Torre para rescatar a la princesa
For the word sacudir in Present tense it’s sacude
And for preterite tense it’s sacudió