This is directly from Tuckerman's Statistical Mechanics textbook, Chapter 12.6

The part that gets me confused starts from the 2nd line of eqn. (12.6.38) to the first line of eqn.(12.6.39), I can't follow how it's derived? It would be much appreciated if I can get some hints here!