@AlexMe this is how you get the second line in @statsplease 's answer.
Apply Leibniz Integral Rule to get the derivative of C(q,q) with respect to q. You'll have to apply it twice because it is a double integral and the upper limits of integration of both integrals will be q. The result is: