F. Distinct of Distincts
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a grid with $$$n$$$ rows and $$$m$$$ columns. Consider the following process:

  • For each row $$$i$$$ ($$$1 \leq i \leq n$$$), count the number of distinct integers in that row. Let this count be $$$r_i$$$.
  • For each column $$$j$$$ ($$$1 \leq j \leq m$$$), count the number of distinct integers in that column. Let this count be $$$c_j$$$.
  • Form a set $$$S = \{r_1, r_2, \ldots, r_n, c_1, c_2, \ldots, c_m\}$$$ containing all these $$$n + m$$$ counts.

Your task is to fill the grid with integers from $$$1$$$ to $$$10^{9}$$$ in such a way that the number of distinct elements in the set $$$S$$$ is maximized.

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \cdot m \le 3 \cdot 10^5$$$) — the number of rows and columns of the grid.

It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$3\cdot 10^{5}$$$.

Output

For each test case, the first line should contain a single integer — the maximum possible number of distinct elements in the set $$$S$$$.

Then, output $$$n$$$ lines, each containing $$$m$$$ space-separated integers. The $$$j$$$-th integer in the $$$i$$$-th line should be the element in the $$$i$$$-th row and $$$j$$$-th column of the grid. All integers in the grid must be from $$$1$$$ to $$$10^9$$$.

If there are multiple possible grids, output any of them.

Example
Input
2
2 2
1 4
Output
2
2 5
5 5
2
6 2 3 6

Note

In the first test case, for the output grid:

  • The first row has elements $$$\{2, 5\}$$$, so $$$r_1 = 2$$$ as there are 2 distinct elements.
  • The second row has elements $$$\{5, 5\}$$$, so $$$r_2 = 1$$$.
  • The first column has elements $$$\{2, 5\}$$$, so $$$c_1 = 2$$$.
  • The second column has elements $$$\{5, 5\}$$$, so $$$c_2 = 1$$$.
So, the set $$$S = \{r_1, r_2, c_1, c_2\} = \{2, 1, 2, 1\}$$$ has $$$2$$$ distinct elements. It can be shown that no other grid has more than $$$2$$$ distinct elements in $$$S$$$.

In the second test case, for the output grid:

  • The first row has elements $$$\{6, 2, 3, 6\}$$$, so $$$r_1 = 3$$$.
  • The first column has elements $$$\{6\}$$$, so $$$c_1 = 1$$$.
  • The second column has elements $$$\{2\}$$$, so $$$c_2 = 1$$$.
  • The third column has elements $$$\{3\}$$$, so $$$c_3 = 1$$$.
  • The fourth column has elements $$$\{6\}$$$, so $$$c_4 = 1$$$.
So, the set $$$S = \{r_1, c_1, c_2, c_3, c_4\} = \{3, 1, 1, 1, 1\}$$$ has $$$2$$$ distinct elements and this is the maximum possible.