Alice and Bob are playing a game. Alice takes a paper with N ×M points arranging in N rows and M columns. First, Alice colors some points with one of 5 colors: c
0,c
1,c
2,c
3,c
4. And then, Bob draws some lines between adjacent points which own a common edge. If the color of a point is c
i, Bob must draw exactly i lines linking this point. Otherwise, Bob can draw any number of lines linking it. At last, Alice would color the rest points, with the same rules that the point which links i lines should be painted the color c
i. After the game, Alice might get different patterns of the colors. Suppose the initial colored paper can lead to totally K patterns, and there are P
i ways for Bob to draw lines for the i-th patterns. Alice wants to know

输入描述:
The first line of input contains an integer t which is the number of test cases. Then t test cases follow. For each test case, the first line consists of two integers N(N ≤ 66), and M(M ≤ 6). The i-th line of the next N lines contains M integers, and among them the j-th integer donates the point (i,j). If the point is panted color ci, the integer is i, otherwise it is −1.
输出描述:
For each test cases, output
modulo 10007.
示例1
输入
复制
2
2 2
-1 -1
-1 -1
3 3
1 1 1
1 0 1
1 1 1
说明
In the first case, there would be 15 patterns:
There is only one way to draw lines which leads to above 14 patterns respectively.

There are two ways to draw lines which lead to above pattern. Therefore the answer is 18 = 14 + 2
2.