Suppose we have topological spaces $B\subset A\subset X$ and $B'\subset A'\subset X'$, and a continuous map $f:X\to X'$ with $f(A)\subset A'$, $f(B)\subset B'$. Consider the homotopy long exact sequence of the triples $(X,A,B)$ and $(X',A',B')$. $f$ induces a chain map between the two sequences. I am trying to prove the five-lemma in the following special form: If the maps $\pi_i(X,B)\to \pi_i(X',B')$ and $\pi_i(X,A)\to \pi_i(X',A')$ $(i=1,2)$ induced by $f$ are bijections for **all** choices of basepoints (in $B$), then so is the middle map $\pi_1(A,B)\to \pi_1(A',B')$. (This is a part of an exercise in Hatcher's algebraic topology, section 4.1, problem 9.)

I got stuck showing injectivity. Here is my attempt: fix a basepoint $x_0\in B$ and $y_0:=f(x_0)$. Suppose $[\gamma_1],[\gamma_2]\in \pi_1(A,B,x_0)$ and $f_*[\gamma_1]=f_*[\gamma_2]$. Then there is a homotopy $F$ of $f\circ \gamma_1$ to $f\circ \gamma_2$ through maps $(I,\partial I, \{1\})\to (A',B',y_0)$. On the other hand, by injectivity of $\pi_1(X,B)\to \pi_1(X',B')$, $[\gamma_1]=[\gamma_2]$ in $\pi_1(X,B,x_0)$ so there is a homotopy $G$ of $\gamma_1$ to $\gamma_2$ through maps $(I,\partial I, \{1\})\to (X,B,x_0)$. Comparing with the usual proof of five lemma, it seems that I have to proceed as follows:

using $F$ and $fG$, produce an element of $\pi_2(X',B')$.

use surjectivity of $\pi_2(X,B)\to \pi_2(X',B')$ and 1 to get an element of $\pi_2(X,B)$.

use 2 (and maybe with $G$) and injectivity of $\pi_2(X,A)\to \pi_2(X',A')$ to get a homotopy through maps $(I^2,\partial I^2, J^1)\to (X,A,x)$

using the homotopy from 3, obtain a homotopy of $\gamma_1$ and $\gamma_2$ through maps $(I,\partial I, 1)\to (A,B,x_0)$ and conclude that $[\gamma_1]=[\gamma_2] \in \pi_1(A,B,x_0)$