The first thing we are going to do for this case is to define a variable.
x: speed of the trolley
Then, by definition we have to:

Where,
t: time
d: distance
v: speed
For the bus we have:

For the trolley we have:

Since the time is the same then we have:

From here, we clear the value of x:

So, the speed of the trolley is:

The bus speed is:
Answer:
Trolley: 18 m / h
Bus: 24 m / h