How to give a context-sensitive grammar for a^nba^nba^nb?
One possible grammar is:

\begin{align}
S&amp;\rightarrow Tb &amp;(1)\\
T&amp;\rightarrow AXY &amp;(2)\\
T&amp;\rightarrow ATXY &amp;(3)\\
YX&amp;\rightarrow YZ &amp;(4)\\
YZ&amp;\rightarrow WZ &amp;(5)\\
WZ&amp;\rightarrow WY &amp;(6)\\
WY &amp;\rightarrow XY &amp;(7)\\
AX &amp;\rightarrow AbA_X &amp;(8)\\
A_XX&amp;\rightarrow A_XA_X &amp;(9)\\
A_XY&amp;\rightarrow A_XbA_Y &amp;(10)\\
A_YY&amp;\rightarrow A_YA_Y &amp;(11)\\
A&amp;\rightarrow a &amp;(12)\\
A_X&amp;\rightarrow a &amp;(13)\\
A_Y&amp;\rightarrow a &amp;(14)
\end{align}

We can generate $A^n(XY)^n$ using Rule (1) to (3). Rule (4) to (7) are used to change $YX$ to $XY$, thus we can generate $A^nX^nY^n$. At last, using Rule (8) to (14) we can generate $a^nba^nba^nb$. 

Note we needn't worry that in a pattern $YX$, $Y$ yields to $A_Y$ (or $bA_Y$) before we exchange $X$ and $Y$, because otherwise there is no rule to eliminate $X$ in this pattern.