The first $2007$ positive integers are each written in base $3$. How many of these base-$3$ representations are palindromes? (A palindrome is a number that reads the same forward and backward.)

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