Divide by a2?

Please use parentheses to clarify meaning. In this case, a1 sqrt(2gh/(a1/a2)-1) = q would have been helpful.

Please don't use implicit multiplication. Use an effective symbol. In this case, a1 * sqrt(2gh/(a1/a2)-1) = q would have been helpful.

Use "^" to indicate exponentiation. 2gh/(a1/a2)-1 = (q^2) / (a1^2) = (q/a2)^2