we need to follow the sign convention for workdone. When gas expands, volume increases, work is done by gas and sign is negative.
When we compress the gas, volume decreases, work is done on the gas and sign is positive.
for the path iaf, it is given ΔQ = 50 and Δw=-20 (negative sign because gas expands, work is done by gas)
Internal energy ΔE between state f and stae i is given by ΔE = ΔQ+ΔW = 50-20 = 30J
from i to f internal energy increases. In the returning path from f to i internal energy decreases, but gas is compressed hence workdone is positive.
In the retruning pathfi, ΔE = ΔQ+ΔW , or -30 = ΔQ+13 , or ΔQ = -43J
Heat energy should be released when the state changes from f to i, hence it is negative.