Solution (source code)

= Solution

Put $\mu_\star=GM_\star$. Conservation of <specific orbital energy> and <specific angular momentum> gives
$$
a=\frac{Q+q}{2},\qquad h^2=\frac{2\mu_\star qQ}{Q+q},\qquad
v_c^2=\mu_\star\left(\frac2{a_p}-\frac2{Q+q}\right),\qquad v_p^2=\frac{\mu_\star}{a_p}.
$$
The last <comet> expression is the <vis-viva equation> at the <planet>'s orbit. The <planet> has only tangential velocity, while the <comet>'s tangential component is $v_t=h/a_p$. Consequently its prograde <relative velocity> is exactly, before planetary deflection,
$$
\frac{v_{\rm rel}^2}{v_p^2}=3-\frac{2a_p}{Q+q}-2\sqrt{\frac{2qQ}{a_p(Q+q)}}.
$$
In the near-parabolic encounter limit $Q\gg a_p$, this reduces to
$$
\boxed{v_{\rm rel}\simeq v_p\left[3-2\sqrt{2q/a_p}\right]^{1/2}.}
$$
\b[The displayed approximation also requires $Q\gg a_p$.] The assumptions $Q\gg q$ and $q\ll a_p$ alone do not guarantee it: an orbit with $Q=a_p$ encounters the <planet> near <apoapsis> and has $v_{\rm rel}\simeq v_p$, not $\sqrt3v_p$.

If all coplanar near-parabolic planet-crossing <comets> are admitted, so that $0\leq q\leq a_p$, the tangential component ranges from $-\sqrt2v_p$ to $+\sqrt2v_p$ when retrograde orbits are included. Thus
$$
\boxed{(\sqrt2-1)v_p\leq v_{\rm rel}\leq(\sqrt2+1)v_p.}
$$
For prograde orbits alone the upper limit is $\sqrt3v_p$; for the stated deep-crossing limit $q\ll a_p$, both prograde and retrograde encounters approach $\sqrt3v_p$. These are the speeds outside the <planet>'s gravitational well. The surface impact speed is $v_{\rm imp}=\sqrt{v_{\rm rel}^2+v_{\rm esc,p}^2}$, where $v_{\rm esc,p}$ is the planetary <escape velocity>; under negligible <gravitational focusing> the two speeds agree.