Grammar for all words other than $wq,qw$
How about
\begin{align*}
S&amp;\to q\mid w\mid qqB \mid wwB \mid qwA\mid wqA\mid \varepsilon \\
A&amp;\to qB\mid wB \\
B&amp;\to qB\mid wB\mid \varepsilon
\end{align*}
We can just explicitly include strings of length 0, 1 or 2 that are allowed, but add another non-terminal after the length two strings which are not allowed to force us to add at least one more terminal, then make sure after that we can add any letters we want in any order.