Solution (source code)

= Solution

Under $H_0$, write the <singular value decomposition>
$$
X=UDV^T,\qquad D_{jj}=\sqrt{\lambda_j}.
$$
Then
$$
\widehat\beta
=VD^{-1}U^T\varepsilon.
$$
The coordinates of $U^T\varepsilon/\sigma$ are independent standard normal variables. Hence
$$
\frac{\|\widehat\beta\|^2}{\sigma^2}
\mathrel{\overset d=}
\sum_{j=1}^p\lambda_j^{-1}W_j,
\qquad
W_j\sim\chi^2_1
$$
independently. By parts (ii) and (iii),
$$
Z=\frac{n\widehat\sigma^2}{\sigma^2}\sim\chi^2_{n-p}
$$
is independent of all the $W_j$. Consequently
$$
\boxed{
T\mathrel{\overset d=}
\frac{\sum_{j=1}^p\lambda_j^{-1}W_j}{Z}
}.
$$