ohhh, okay. i get it.
let's assume the distance from A to B is d, so the total distance is 2d.
then, using d=st, you find that the time from A to B is d/40 and from B to A is d/120
so the total time = d/40 + d/120
and the average speed = 2d / (d/40 + d/120)
= 2d / (3d/120 + d/120)
= (2d x 120) / 4d
= 240d / 4d
= 60