Modify the output master to accept three types of messages from the slaves. These types are The master continues to receive messages until it has received an exit message from each slave. For simplicity in programming, have each slave send the messages

Hello from slave 3
Goodbye from slave 3

with the ordered output mode, and

I'm exiting (3)

with the unordered output mode.

You may want to use these MPI routines in your solution:
MPI_Comm_split MPI_Send MPI_Recv