Let $p$ be an odd prime number, and let ${\Bbb {F}}_p$ denote the field of integers modulo $p$. Let ${\Bbb {F}}_p[x]$ be the ring of polynomials over ${\Bbb {F}}_p$, and let $q(x)\in {\Bbb {F}}_p[x]$ be given by
$$q(x)=\sum\limits_{k=1}^{p-1}a_kx^k,$$
where
$$a_k=k^{(p-1)/2}\mod p.$$ 
Find the greatest nonnegative integer $n$ such that $(x-1)^n$ divides $q(x)$ in ${\Bbb {F}}_p[x]$. What is the answer when p = 3?

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