A simple rearrangement says that Q = Fd /(d*A) = 1/2 * rho * v^2. So, max Q isn't max drag, but the max ratio of drag compared to the drag coef times the, in this case, mass. Assuming a single rocket stage for simplicity's sake means that Q is highest later in the stage, when mass of the stage is lower due to propellant loss and velocity is up because of the burn. I suspect, however, that thrust to weight ratio has a relationship in that it is what can push your velocity higher in relation to rho. As for the calculus, I'm thinking this leads to partial derivatives in order to get around the circular nature of the acceleration vector being determined by velocity but it's been so long that I can't remember exactly where to go without a refresher. And then you have to remember that if you're doing a gravity turn, your time at a given pressure altitude is longer. Boy this can get complicated quick. I'm gonna keep working on this. I'm interested in what you find out.