Trex swings to loss in the third quarter