Set Up The Flag
题号:NC219804
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

You are given a matrix of rows and columns, for each grid , there is an integer on it, and the other grids are empty.
                                        
                        One of the way to set up flags in the second sample.
You have to set up flags in empty grids. For the grid with an integer on it, the amount of flags in the surrounding grids needs to be equal to this integer.
Please calculate how many ways to set up the flag, two ways are considered different if and only if at least one flag is seted up in a different grid.

输入描述:

The first line contains an integer  — the number of test cases, each test case given a matrix of  rows and  columns,  representing the integer on grid  .

输出描述:

For each test case, please output an integer to indicate how many ways to set up the flags.
示例1

输入

复制
2
1 0 0
0 0 0
0 0 0
2 3 3
1 2 1
1 1 1

输出

复制
3
34542

说明

For the first example, there are only three ways to set up the flag:
We can set up the flag at (1,1)_{} or (1,2)_{} or (2,1)_{} , and the other grid must be empty.