a^2 - ap + p^2 - 3q
We will consider "a" as the variable of interest
We can write
a^2 + pa = 3q - p^2
Take (1/2) of p = p/2 square this = p^2 / 4 add to both sides
a^2 +pa + p^2/4 = 3q - p^2 + p^2/4
Factor the left side simplify the right
(a + p/2)^2 = [ 12q - 4p^2 + p^2 ] / 4
Take both roots
(a + p/2) = ±√ [ 12q - 3p^2 ] / 2
Subtract p/2 from both sides
a = ±√ [ 12q - 3q^2 ] / 2 - p/2
a = - p ±√[12q - 3q^2]
_________________
2