Let $f(x) = (ax^2+\sin x) (p+q \: \cos x)$

By product rule

$f'(x) =(ax^2+\sin x)\large\frac{d}{dx}$$(p+q \cos x)+(p+q \cos x)\large\frac{d}{dx}$$(ax^2+\sin x)$

$ = (ax^2+\sin x)( -q\: \sin x)+(p+q \cos x)(2ax+ \cos x)$

$ = -q\sin x(ax^2+\sin x)+(p+q \cos x)(2ax+ \cos x)$