For the case x > 0, show that z must be even, and hence factorize 3x as the difference of two squares. Then proceed by considering each of these factors, modulo 3.