An ALMA spectroscopic survey of the brightest submillimeter galaxies in the SCUBA-2-COSMOS Field (AS2COSPEC): physical properties of z = 2-5 ultra- and hyperluminous infrared galaxies