as you know, a cube has all equal dimensions, thus length=width=height = x, check the picture below.
that means the square pyramid has a base of a 3x3 square, and its height is also 3, thus
[tex]\bf \textit{volume of a pyramid}\\\\
V=\cfrac{1}{3}Bh~~
\begin{cases}
B=area~of\\
\qquad its~base\\
h=height\\
------\\
B=\stackrel{3\times 3}{9}\\
h=3
\end{cases}\implies V=\cfrac{1}{3}(9)(3)[/tex]