4901. Moonlight over the Lotus Pond

单点时限: 1.0 sec

内存限制: 256 MB

Hazy moonlight poors on n×m ponds,which are lined up as a matrix with n rows and m columns.

The pond located at the i-th row and the j-th column contains ai,j lotus flowers (where 1in,1jm).

Now,the Plovery Frog plans to choose a sub-matrix,and then merge all of the ponds in it. And he hopes that the huge merged ponds will contains exactly k lotus flowers.

So,the Plovery Frog wants to know that,how many different ways choosing the sub-matrix can meets his requirement.

In other words,

he wants to know the number of tuples in format (l1,r1,l2,r2), 1l1r1n,1l2r2m ,which makes below constraint satisfied:
(i=l1r1j=l2r2ai,j)=k

输入格式

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

There are T test cases, for each one:

The first line contains 2 integers n,m (1n,m105) ,denoting the number of the rows and columns in the matrix.

For the next n lines, each line contains m integers,the integer located at the i-th line and the j-th column is ai,j (0ai,j109).

The next line contains an integer, k (0k1014) , denoting the required sum of the elements in the sub-matrix.

For all of the T test cases,n×m2×105 is satisfied.

输出格式

For each test case, output a line, which contains an integer as your answer.

样例

Input
2
2 2
1 9
0 5
1
5 5
3 1 4 1 5
9 2 6 5 3
5 3 8 4 6
2 6 4 3 3
8 3 2 7 9
19
Output
2
7

58 人解决,127 人已尝试。

66 份提交通过,共有 1067 份提交。

5.7 EMB 奖励。

创建: 2 年,6 月前.

修改: 2 年,6 月前.

最后提交: 2 年,1 月前.

来源: N/A

题目标签