Using the first law of thermodynamics, ΔU=q+w.
For the process from state X to state Y:
Heat absorbed by the gas, qX→Y=+10 J
Work done by the gas, wX→Y=−18 J
Change in internal energy, ΔUX→Y=qX→Y+wX→Y=10−18=−8 J
For the reverse process from state Y to state X:
Change in internal energy, ΔUY→X=−ΔUX→Y=+8 J
Heat evolved by the gas, qY→X=−6 J
Let the work done on the gas be wY→X.
ΔUY→X=qY→X+wY→X
8=−6+wY→X
wY→X=+14 J
Since the work done is positive, 14 J of work is done on the gas by the surrounding.
Answer: 14 J of the work is done on the gas 'A' by the surrounding.