P15778 [JAG 2025 Summer Camp #3] Spray on Surface

Description

Consider an $N \times N \times N$ region with opposite corners at $(0,0,0)$ and $(N,N,N)$. Within this region, an object is built from $1 \times 1 \times 1$ blocks. Each block occupies exactly the unit cube $[i, i+1] \times [j, j+1] \times [k, k+1]$ for some integers $0 \leq i, j, k < N$. It is guaranteed that this object is connected and that it contains no cavities (i.e., every empty cell is connected to the exterior of the $N \times N \times N$ region). You want to know the amount of spray paint required to paint the surface of this object. Compute the surface area of the object.

Input Format

The input consists of multiple test cases. The first line contains an integer $T$ ($1 \leq T \leq 100$), representing the number of test cases. $T$ test cases follow. Each test case is given in the following format. $$ \begin{aligned} & N \\ & S_{1,1} \\ & S_{1,2} \\ & \vdots \\ & S_{1,N} \\ & S_{2,1} \\ & \vdots \\ & S_{N-1,N} \\ & S_{N,1} \\ & \vdots \\ & S_{N,N} \end{aligned} $$ For each test case, the first line contains an integer $N$ ($1 \leq N \leq 10$), representing the side length of the region containing the object. The following $N^2$ lines each contain a string $S_{i,j}$ of length $N$, representing the shape of the object. If the $k$-th character of $S_{i,j}$ is ‘#’, then there is a block in the region $[i, i+1] \times [j, j+1] \times [k, k+1]$. If it is ‘.’, there is no block in that region. The object satisfies the conditions in the problem statement.

Output Format

For the $T$ test cases, output the answers on separate lines. For each test case, output the surface area of the object on a single line.