Let's look at the differences in speed each hour.....
hour
1 2 3 4 5 6 7 8 9 10
diff
-4 -3 -2 -1 0 1 2 3 4 5
so at hour 5 they are the same speed....then the originally slower train starts gaining so that at hour 9 it has made up the miles it lost in the first 4 hours of going slower
at hour 9 they should be at the same point
check: 9 hr (40 km/hr) = 360 km
other train 36 + 37 +38 +39 +40 +41 +42 + 43 + 44 = 360 km