Strap on your seal belts. We're going to need a lot of applications of the chain rule. If h ( x ) = f ( g ( x ) ) {\displaystyle h(x)=f(g(x))} for differentiable f and g, then the chain rule states that
h ′ ( x ) = f ′ ( g ( x ) ) g ′ ( x ) {\displaystyle \displaystyle h'(x)=f'(g(x))g'(x)}