Prove $g$ is a generator if $g^q=1 \pmod p$

Let $p$ be an odd prime and let $q=\frac{p-1}{2}$. If $g^q=-1\pmod p$ and $q$ is a prime, show that $g$ is a primitive root mod $p$.

I want to show $\{g,g^1,...,g^{p-1}\}=\{1,2,...p-1\}$. I argue by contradiction that if there're $x,y\in \{1,2,...p-1\},x<y,g^x=g^y\pmod p$. Then $g^{y-x}=1\pmod p$. I don't know how to use the fact that $q$ is prime to lead to a contradiction.


Hint

If ord$_pg=d,d$ must divide $\phi(p)=2q$

So, $d\in[1,2,q,2q]$

If $d=1,g^q\equiv1^q\not\equiv-1\pmod p$

So, $d=2$ or $d=2q=p-1$ or $d=q$


By definition, $\,g\,$ is a primitive root $\bmod p=2q+1\!\iff\! g\, $ has order $\,p-1 = 2q,\,$ which, by the Theorem below, is true $\!\iff\! a := g\not\equiv -1\pmod{p}$

Theorem $ $ Let $\,q\,$ be a prime, and $\,a\in \rm Z,\,$ a domain where $\,2\neq 0\,$ (e.g. $\,{\rm Z} = \Bbb Z_p,\, $ prime $\,p>2).$

$${\rm if}\ \ a^{\large q}= -1\ \ \ {\rm then}\ \ \ a\ \ {\rm has\ order}\ \ 2q\iff a\neq -1\qquad $$

Proof $\,\ a^{\large 2q}\! = (a^{\large q})^{\large 2}\!=1,\,$ so, by the Order Test, $\,a\,$ has order $\,2q\iff a^{\large 2}\neq 1,\,$ and $\,a^{\large q}\neq 1,\,$ since $\,2,q\,$ are the only prime divisors of $\,2q\,$ (by unique factorization). Both inequalites are true:

  • $a^{\large q} = 1 \,\Rightarrow\, 1 = a^{\large q} = -1\,\Rightarrow\, 2=0,\, $ contra hypothesis. In particular: $\,\ \color{#c00}{a\neq 1}$
  • $a^{\large 2} = 1\,\Rightarrow\,\underbrace{(a\!-\!1)(a\!+\!1) = 0\,\Rightarrow\,a = \pm1}_{{\rm\large by\ \ Z\ \ a\ \ domain}}.\,$ By hypothesis $\,a\neq -1\,$ so $\,\color{#c00}{a = 1}\Rightarrow\!\Leftarrow$