<p>Given an <code>m x n</code><code>matrix</code>, return <em>a new matrix </em><code>answer</code><em> where </em><code>answer[row][col]</code><em> is the </em><em><strong>rank</strong> of </em><code>matrix[row][col]</code>.</p>
<p>The <strong>rank</strong> is an <strong>integer</strong> that represents how large an element is compared to other elements. It is calculated using the following rules:</p>
<ul>
<li>The rank is an integer starting from <code>1</code>.</li>
<li>If two elements <code>p</code> and <code>q</code> are in the <strong>same row or column</strong>, then:
<ul>
<li>If <code>p < q</code> then <code>rank(p) < rank(q)</code></li>
<li>If <code>p == q</code> then <code>rank(p) == rank(q)</code></li>
<li>If <code>p > q</code> then <code>rank(p) > rank(q)</code></li>
</ul>
</li>
<li>The <strong>rank</strong> should be as <strong>small</strong> as possible.</li>
</ul>
<p>The test cases are generated so that <code>answer</code> is unique under the given rules.</p>
The rank of matrix[0][0] is 1 because it is the smallest integer in its row and column.
The rank of matrix[0][1] is 2 because matrix[0][1] > matrix[0][0] and matrix[0][0] is rank 1.
The rank of matrix[1][0] is 2 because matrix[1][0] > matrix[0][0] and matrix[0][0] is rank 1.
The rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0], and both matrix[0][1] and matrix[1][0] are rank 2.