By application of calculus of residues, prove that $$ \int_{0}^{2\pi} \frac{\cos^{3}\left(3\theta\right)} {1 - 2p\cos\left(2\theta\right) + p^{2}} \,\mathrm{d}\theta = \frac{\pi\left(1 - p + p^{2}\right)}{1 - p} $$ I have attempted the above question using the substitution $z = \mathrm{e}^{\mathrm{i} \theta}$ and I have also used the substitution $\cos\left(x\right) = \mathrm{e}^{\mathrm{i}\theta}$ but I didn't get the solution correctly.
Solution \begin{equation*} \text{Let}\, z=e^{i\theta}\, \hspace{2mm} dz=ie^id\theta,\,\hspace{2mm} dz=izd\theta\\ \end{equation*} \begin{equation*} \cos\theta=\frac{z+z^{-1}}{2}\\ \end{equation*} \begin{equation*} \cos2\theta=\frac{z^2+z^{-2}}{2}\\ \end{equation*} \begin{equation*} \cos3\theta=\frac{z^3+z^{-3}}{2}\\ \end{equation*} \begin{equation*} \begin{split} \int_0^{2\pi} \frac{\cos ^3{3\theta}d\theta}{1-2p\cos 2\theta+p^2} &= \oint\frac{(\frac{z^3+z^{-3}}{2})^3}{1-2p(\frac{z^2+z^{-2}}{2})+p^2}\cdot\frac{dz}{iz}\\ &= \frac{1}{8}\oint\frac{-(z^3+z^{-3})^3i}{[z-p(z^3+z^{-1})+p^2z]}\cdot dz\\ &= \frac{1}{8}\oint\frac{(z^3+1)^3i}{z^8[pz^4+(p^2+1)z^2-p]}\cdot dz \end{split} \end{equation*} There is a pole at z=0 of order 8. Kindly help, to determine the remaining poles and the residues.