let the speed of the passenger train be v mph, then the speed of the freight train is v-20 mph.

When the trains pass the passenger train has been running for 3 hrs and the freight train has been running for 5 hrs and they gave run the same distance so:

3v=5(v-20)

which you solve for v.

CB