There is another way to multiply two matrices, called the tensor product (Kronecker product).
Let $A$ be a $p \times q$ matrix and $B$ an $n \times m$ matrix, where neither $A$ nor $B$ is a $1 \times 1$ matrix.
The tensor product $A \otimes B$ is a $pn \times qm$ matrix obtained by replacing every entry $a_{ij}$ of $A$ with the block $a_{ij} \cdot B$.
For example:
$$A = \begin{bmatrix} 1 & 2 \ 3 & 4 \end{bmatrix}, \qquad B = \begin{bmatrix} 0 & 5 \ 6 & 7 \end{bmatrix}$$
$$A \otimes B = \begin{bmatrix} 0 & 5 & 0 & 10 \ 6 & 7 & 12 & 14 \ 0 & 15 & 0 & 20 \ 18 & 21 & 24 & 28 \end{bmatrix}$$
Unlike ordinary matrix multiplication, there is no requirement that $q$ equal $n$.
Given a matrix, write a program that counts the number of different ways it can be written as a tensor product $A \otimes B$, where $A$ and $B$ are matrices whose entries are positive integers and neither is a $1 \times 1$ matrix. Two ways are considered different when the matrix $A$ or the matrix $B$ differs, either in size or in any entry.
The input consists of several test cases.
The first line of each test case contains the matrix dimensions $r$ and $c$. Each of the next $r$ lines contains the $c$ integers of one row of the matrix.
$r$ and $c$ are at most $500$, and every entry of the matrix is an integer between $1$ and $65536$ inclusive.
The last line of the input contains two zeros, marking the end of the input.
For each test case, print on its own line the number of different ways the given matrix can be expressed as a tensor product $A \otimes B$.