I just remembered something about involute gear teeth profiles. Ideally, they don't slide, they roll on each other. That means the friction would not change the answer and the correct output torque is identical to the load of 40 Nm.

Now if you have a non-involute tooth face (a bad idea) then you will get sliding at the contact point and then the direction of rotation will make a difference.