F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Undercity

Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 51    Accepted Submission(s): 33


Problem Description
$\space \space$*How many times have you died in WarCraft because of falling off the UnderCity's elevator?*

$\space \space $*How many times have you traveled through the labyrinthine city but couldn't find the auction house?*

$\space \space$*Undercity is a maze itself!*


Undercity's map can be seen as an $n \cdot m$ 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!
 

Input
The input consists of multiple test cases.

The first line contains an integer $T\ (1\leq T\leq10)$ denoting the number of test cases.

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

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

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

Sample Input
2 2 2 ab cd 2 2 aa aa
 

Sample Output
1 9
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-04-01 08:45:23, Gzip enabled