This is completing the square.

Start by assigning g^2 as anything u like, in this case, I'll do Y. It just makes life easier for you.

g^2 = Y, rewrite the equation to get Y^2 + 18Y + 24.

Complete the Square to get: (Y+9)^2 + 24 - 81

So the answer to the question has to be 24-81 = __