Masco swings to profit in third quarter