The concept of Work is closely related to that of energy.
Work is associated with forces that overcome resistance.
Work W was performed in raising mass B , while mass A has given up its potential energy. The work performed in raising B was again invested in potential energy. With ideal pulleys, strings etc., that energy again equals W, illustrating the conservation of energy . In an ideal set-up with no losses, this energy could be used to raise A to its previous height. If the force of sliding friction of the block on the tabletop is exactly equal to mg, then dropping A allows the block to slide a distance h and overcome F along it.