Direct conversion of a three-atom W state to a Greenberger–Horne–Zeilinger state in spatially separated cavities