A particle $P$, of mass $m$, is able to move in a vertical circle on the smooth inner surface of a sphere with centre $O$ and radius $a$. Points $A$ and $B$ are on the inner surface of the sphere and $AOB$ is a horizontal diameter. Initially, $P$ is projected vertically downwards from $A$ with speed $\sqrt{\frac{21ag}{2}}$. At the lowest point of its path, vertically below $O$, the particle $P$ collides with a stationary particle $Q$, of mass $4m$, and rebounds. The speed acquired by $Q$ as a result of the collision is just sufficient for it to reach $B$.
(i) Find the speed of $P$ and the speed of $Q$ immediately after their collision. [7]
In its subsequent motion, $P$ loses contact with the inner surface of the sphere at the point $D$, where the angle between $OD$ and the upward vertical through $O$ is $\theta$.
(ii) Find $\cos\theta$. [5]