I have a group ( are words on a, b and are the relations) and define a function,

such that and in for all , then is a surjective endomorphism (homomorphism)?

Basically, if I stipulate that the generators are sent to other generators and the relators still hold, then is it a homomorphism (the surjection easily follows)?