
Most people know how to multiply two matrices. However, there exists another form of multiplication, known as tensor multiplication, which works more as one might expect matrix multiplication would. Let A be a × matrix and B a × matrix, where neither A nor B is a 1 \times 1 matrix. The tensor product AB is a × matrix, formed by replacing each element a_{ij} in A with the matrix (a_{ij}) \cdot B. Two examples are shown below, which also demonstrate that, like ordinary matrix multiplication, tensor multiplication is non-commutative:

Note that unlike ordinary matrix multiplication, there is no requirement that the number of columns in the first matrix equals the number of rows in the second. The goal of this problem is to determine the number of ways a given matrix can be formed as the result of a tensor multiplication, if any.
The first line of input for each test case contains two positive integers and denoting the number of rows and columns in the matrix. The following lines each contain positive integers. The values of and satisfy r, c \leq 500, each entry in the matrix is at most , and the last test case is followed by a line containing .
For each test case, output the number of different ways that the matrix could be the tensor product of two matrices with positive integer entries, neither of which is a 1 \times 1 matrix.
Example 1