One sufficient condition can be derived in the following way: Let $p=-(1+\epsilon)/2+(p+(1+\epsilon)/2)$, where $\epsilon>0$. Then using the Cauchy inequality one can find that
$$
\sum_{n=1}^Nn^p\sqrt{a_n}=\sum_{n=1}^Nn^{-(1+\epsilon)/2}n^{p+(1+\epsilon)/2}\sqrt{a_n}\le\sqrt{\sum_{n=1}^Nn^{-(1+\epsilon)}\sum_{n=1}^Nn^{2p+1+\epsilon}a_n}.
$$
Hence, if the series $\displaystyle\sum_{n=1}^{\infty} n^{2p+1+\epsilon}a_n$ converges, then $\displaystyle\sum_{n=1}^{\infty} n^p\sqrt{a_n}$ converges as well, so it's sufficient to set $q=2p+1+\epsilon$ where $\epsilon$ is an arbitrary small positive number.
Also, I'd like to say that generally you can't choose $q$ less than that. For $q=2p+1$ there's an example of $a_n=\dfrac1{n^{2p+2}\ln^2 n}$ where
$$
\sum_{n=1}^{\infty} n^{2p+1}a_n=\sum_{n=1}^{\infty}\frac1{n\ln^2 n}<+\infty,
$$
but
$$
\sum_{n=1}^{\infty} n^p\sqrt{a_n}=\sum_{n=1}^{\infty}\frac1{n\ln n}=+\infty.
$$