Let f(x) = px + q and g(x) = mx + n. Then f (g(x)) = g (f(x)) is equivalent to
Notice that after simplifying, f(n) = g(q) is left. The method is simple: formula → substitution → calculation → answer.
Ref: NCERT Mathematics Class XI — Sets, Relations and Functions