8637: Undercity

内存限制:512 MB 时间限制:15 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Undercity's map can be seen as an nm matrix, each cell of the matrix contains a lowercase English letter. A path is a sequence of cells such that two neighbouring cells share one edge and the next cell can be reached from the previous cell by only moving right or down.

The city is a little bit weird, so one can only travel through a palindromic path.

A palindromic path is a path such that if you view the letters on all the cells from the starting point to the ending point of the path as a sequence, the sequence is equal when you read from left to right and from right to left.

A way of covering is considered magic if and only if all cells of the matrix are covered by exactly one palindromic path.

Two magic coverings are considered different if and only if there is at least one cell that is covered by different paths in two ways.

Sylvanas believes it's a fulfilling mission to find the number of magic coverings in the city.

Let's help her to do it!

输入格式

The input consists of multiple test cases.

The first line contains an integer T (1T10) denoting the number of test cases.

In each test case, the first line contains two integers n,m(n,m6), denoting the size of matrix.

The following n lines, each line contains mm lowercase English letters, describing the matrix.

输出格式

For each test case, output one line containing one integer, denoting the answer

输入样例 复制

2
2 2
ab
cd
2 2
aa
aa

输出样例 复制

1
9