To be on the verge of losing contact with the loop (at the top) means the normal force is vanishingly small. In this case, Newton’s second law along the vertical direction (+y downward) leads to
which gives us . Recalling previous remarks about the radial acceleration, Newton’s second law applied to the horizontal axis at Q leads to