Answer
$20$ $J$
Work Step by Step
In the first situation, no work is done and there is net energy influx of $30$ $J$. Since the final state is the same in both situations, the same energy must be input in both situations, so work of magnitude $50-30 = 20$ $J$ must be done.