Your diagram should be a right triangle, with these:

---top leg, horizontal leg = say, r

---left leg, vertical leg = say, b

---right side, hypotenuse = say, s

where

r = distance travelled by red car---getting longer as time increases.

b = distance to be travelled by blue car----getting shorter as time increases.

s = distance between red and blue cars

So, by Pythagorean Theorem,

s^2 = r^2 +b^2 --------------------------------------(i)

Differentiate both sides of (i) with respect to time t,

2s(ds/dt) = 2r(dr/dt) +2b(db/dt)

s(ds/dt) = r(dr/dt) +b(db/dt) -------------------(ii)

At the said instant in the Problem, in (ii) we know:

r = 8 km

b = 6 km

And it is given that:

dr/dt = 40 km/hr

db/dt = -60 km/hr -----negative because b is decreasing with time.

We don't know:

ds/dt ----------we are spolving for it.

s -----we can get via (i)

s^2 = r^2 +b^2 --------------------------------------(i)

s^2 = 8^2 +6^2

s^2 = 64 +36 = 100

s = 10 km

So, substitute all those into (ii),

10(ds/dt) = 8(40) +6(-60)

ds/dt = 8(4) -6(6)

ds/dt = 32 -36 = -4 km/hr

Therefore, at that instant, the distance between the two cars is decreasing at the rate of 4 km/hr. --------------answer.