Tic-Tac-Toe (also known as Noughts and Crosses) is a simple pencil-and-paper game played by children. Two players take turns drawing their symbol (O or X) in the cells of a $3 \times 3$ grid. The first player to complete a line of three of their own symbols in a row - horizontally, vertically, or diagonally - wins. If the grid fills up without anyone completing a line, the game is a draw. Here is a game the X player has just won.

The game is rather limited, though. An interesting extension is to make it three dimensional, using three $3 \times 3$ grids stacked on top of one another. A real 3D board needs some construction (plastic sets are sold commercially), but you can also play on paper by drawing three 2D grids and imagining them piled above each other. X wins again below.

What about playing in 4, 5, or 6 dimensions? This is the basic idea of Extreme Tic-Tac-Toe (ETTT). ETTT scoring differs from ordinary Tic-Tac-Toe. Instead of stopping the moment one player completes a line, ETTT players keep going until the grid is full (or until they agree to stop). The winner is whoever has the greater number of lines made of their own symbol. Under ETTT rules, X scores 4 and O scores 1 in the following 3D game.

Your task is to write a program that reads N-dimensional ETTT boards and computes the scores.
Here, a line is a set of three distinct cells that lie in a straight row. Along each dimension the coordinate either (1) stays fixed at some value, (2) increases through $1, 2, 3$, or (3) decreases through $3, 2, 1$, and it must vary along at least one dimension. If all three cells of a line hold the same symbol (all X or all O), that symbol's score goes up by one. A line that contains any empty cell (~) scores for neither player.
The input consists of a series of ETTT board configurations. Each configuration starts with a line holding $N$, the dimension of this game ($1 \le N \le 10$). A value of $N = 0$ signals the end of the input.
That is followed by the characters X, O, and ~ giving the value of each cell (~ denotes an empty cell). Each line holds at least $1$ and at most $40$ symbols. To understand the order in which the data is given, imagine the board held in an $N$-dimensional array. With $N = 5$, for example, a cell could be accessed as cell[a][b][c][d][e]. The following pseudocode reads the data in the correct order (ignoring line breaks).
for a = 1 to 3
for b = 1 to 3
for c = 1 to 3
for d = 1 to 3
for e = 1 to 3
read cell[a][b][c][d][e]
So each board holds exactly $3^N$ cells, with the last dimension's coordinate varying fastest. Ignore line breaks and read the symbols in order.
For each board configuration, output the scores for X and for O on one line in the following format.
X scores A and O scores B
Here $A$ is the number of lines made entirely of X and $B$ is the number of lines made entirely of O.