How to generate a context sensitive grammar for www
Intuitively you want to generate three intermediate symbols at a time, and allow the symbols to sort themselves. Let $S$ be the start symbol. The generation rules are:

$$S \rightarrow S A_1 A_2 A_3$$
$$S \rightarrow S B_1 B_2 B_3$$
The sorting rules are as follows: For symbols $X_i,Y_i \in \{A_1,A_2,A_3,B_1,B_2,B_3\}$ such that $j &lt; i$ add the rule:
$$X_i Y_j \rightarrow Y_jX_i$$
In the end we have to turn the intermediate symbols into terminal symbols. Turn the start symbol into another symbol $S_1$ to end the generation phase. 
$$S \rightarrow S_1$$
Push $S_1$ through the string converting symbols to terminal symbols on the way and increment the subscript when done with one word $w$.
For all $i \in \{1,2,3\}$ add the rules:
$$S_i A_i \rightarrow a S_i \; | \; a S_{i+1}$$
$$S_i B_i \rightarrow b S_i \; | \; b S_{i+1}$$
The subscript of $S$ ensures that the symbols are converted in the proper order as the subscript can not decrease. In the end remove $S_3$.
$$ S_3 \rightarrow \varepsilon $$