Optical and infrared spectroscopy of the type IIn SN 1998S: days 3–127