Let $n$ be the number of integer values of $x$ such that $P = x^4 + 6x^3 + 11x^2 + 3x + 31$ is the square of an integer. Find the value of $n$.

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