I tried tackling this problem by first dividing both sides by $a$ so that I get $a^{3(n+1)^2} \equiv 1$ mod 21. I did that so I can use the Chinese remainder theorem (since gcd(3, 7) = 1) to get the equations
$x \equiv 1$ mod 3
and
$x \equiv 1$ mod 7
Then I thought of using Fermat's little theorem to proceed, but that led me nowhere.
Any help is appreciated, thanks!