We calculate the speed by dividing the distance over time:
s = d/t
So the distance described in the problem is always the same, A to B and B to A.
But we are told that;
7 = d/t
7 = 2d/(t + 2)
that is, the first equation say that at speed 7 km/h a distance d is walked in a time t
the second equation say that at a average speed of 7 (that is 8 on one way and 6 in the other: 8 + 6 = 14, half of it), twice the distance is walked in a time equal to the first time plus 2 minutes.
So we have a system of linear equations, 2 of them with two unknowns, we can solve that:
7 = d/t
7 = 2d/(t + 2)
lets simplify them:
7t = d
7(t + 2) = 2d
7t = 2d - 14
we substitute the first in the second:
7t = 2d - 14
7t = d
so:
d = 2d - 14
d = 14
so the distance between A and B is 14 km