Let $p(n) = n^4-6n^2-160$. If $a_n$ is the least odd prime dividing $q(n) = |p(n-30) \cdot p(n+30)|$, find $\sum_{n=1}^{2017} a_n$. ($a_n = 3$ if $q(n) = 0$.)

Let's think step by step and output the final answer within \boxed{}.
user