During the formal language exam, the professor allowed to find a CFG to following language: $\{a^m b^n c^p d^q, m\neq n\wedge p\neq q\}(1)$, because neither he saw a solution (He passed a test without resolve it before!!!) to $L=\{a^m b^n c^m d^n, m\neq n\}(2)$. First language I can resolve in seconds, but I cannot visualizate how to ensure $m=p, n=q$ and to ensure $m\neq n$.
For $(1)$ I only need to construct a CFG to $\{a^m b^n, m\neq n\}$ twice. But for $(2)$ I need to ensure $a^m b^n$ substring is correlated with $c^m d^n$ substring. Someone can see how to build the $(2)$ CFG?