Squares in the sequence $ a3^n+b$ 
Let $a \in \mathbb{N}, b \in \mathbb{Z}$.  Define $n$ to be the largest nonnegative integer such that the sequence $ \{a_1, a_2, \ldots, a_n \}$ consists entirely of squares of natural numbers, where $a_n := a3^n+b$?  For which values of $a,b$ does $n$ achieve a maximum value?

I managed to prove that the sequence is finite for any given $a,b$, but I have not gone further than this.  I would be happy with any hint. Thank you

COMMENT.- I give here a necessary condition that could help anyone who wants to try to get an answer. I am engaged in another task that requires me all my attention so I do not have enough time for try to solve this challenging problem. 
One can use both periodicity of powers of $3$  modulo $10$ and squares modulo ${10}$.
Put $A3^n+B=\square$ with $A\equiv a\pmod{10}$ and $B\equiv b\pmod{10}$. It follows
$a3^n+b\equiv c= 0,1,4,9,6,5\pmod{10}$
$$\begin{cases}a+b=10x+c\\3a+b=10y+c=10x+c+2a\\7a+b=10z+c=10x+c+5a\\9a+b=10w+c=10x+c+8a\end{cases}$$ By simple subtraction of second and third (or third and fourth) equations we get $a=0$.
Consequently one has to study the equations
$$10x3^n+10y+c=z^2;\qquad c=0,1,4,9,6,5$$ or,equivalently, $$10x3^n+10y=(z-\sqrt c)(z+\sqrt c)$$
With the convenient fact that $\mathbb Q(\sqrt5)$ and $\mathbb Q(\sqrt6)$ are norm-Euclidean quadratic fields.
