Let $a_1$, $a_2$, $ ...$ be a sequence of numbers, each either $1$ or $-1$. Show that if $$\frac{a_1}{3}+\frac{a_2}{3^2} + ... =\frac{p}{q}$$for integers $p$ and $q$ such that $3$ does not divide $q$, then the sequence $a_1$, $a_2$, $ ...$ is periodic; that is, there is some positive integer $n$ such that $a_i = a_{n+i}$ for $i = 1$, $2$,$...$.