Using Vieta's formulas for $x^2 - px + q = 0$, the sum of the roots is $\alpha+\beta = p$ and the product is $\alpha\beta = q$. For the new roots $\alpha/\beta$ and $\beta/\alpha$, their sum is $(\alpha^2+\beta^2)/(\alpha\beta) = ((\alpha+\beta)^2 - 2\alpha\beta)/(\alpha\beta)$, which evaluates to $(p^2 - 2q)/q$. The product of the new roots is $(\alpha\beta)/(\alpha\beta) = 1$. The required quadratic equation is $x^2 - ((p^2 - 2q)/q)x + 1 = 0$. Multiplying the entire equation by q yields $qx^2 - (p^2 - 2q)x + q = 0$, which is $qx^2 + (2q - p^2)x + q = 0$.