Inverse spectral problems for linear and quadratic matrix pencils