Heat->mechanical energy can only be (1-Tc/Th) efficient. But mechanical energy->heat can be 1/(1-Tc/Th) efficient, so you can get close to unity round trip efficiency.
That's why people use heat pumps to heat buildings, because you get more heat out than energy in (the extra heat comes from the ground).