St Mirren moved four points above to the bottom two in the Scottish Premiership after winning at Motherwell.