Kaleidoscope#5552

Kaleidoscope

8 secondi
256 megabyte
Molto difficile

You are given a square board divided into n \times n unit squares, each of which is painted with some color. The integer is odd. For every k \leq n, a k \times k sub-square of this board is kaleidoscopic if:

Compute the number of sub-squares of the board that are kaleidoscopic.

Input

The first line contains the number of test cases . The test cases follow.

The first line of a test case contains a single integer (1 \leq n \leq 4000) - the board side length. The next lines describe the rows of the board: each of them contains a word of length over the English alphabet (only lowercase letters). The letters denote the colors of the consecutive unit squares.

Output

For each test case, print a single integer on a separate line - the total number of kaleidoscopic sub-squares of the board.

Esempi

Esempio 1

Loading
Loading