Let's consider, our system to be the bullet as well as the block. Since there is no other external force acting on the system, (gravitational forces can be ignored since the motion is to be considered only in the horizontal direction)
Now,
The initial momentum of the system = mu
Let the velocity of the block after a collision occurs and the bullet again comes out of the block be v1
So, Final momentum = Mv1 + mv
Initial momentum = Final momentum
So,
mu = nmv1 + mv ,
Therefore,
v1 = (u-v)/n
So, the velocity of the block will be (u-v)/n
And , the relative velocity of the bullet with respect to block will be
v - v1 = v-(u-v)/n
= nv+v-u/n
= ((n+1)v-u)/n