The right answer is A. Cuando Carlos y Sofìa estuvieron en Costa Rica, viajaron en tren varias veces.
This means: When Carlos and Sofía were in Costa Rica, they traveled by train several times.
The keywords are "estuvieron" (were), that is the past of "estar". And the "viajaron" (traveled), that is the past of "viajar" (Travel). In the other sentences, the past is not well conjugated.
I hope this information can help you.