You are given an empty grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You should fill this grid with integers in a way that satisfies the following rules:
- For any three cells $c_1$, $c_2$ and $c_3$ such that $c_1$ shares a side with $c_2$ and another side with $c_3$, the integers written in cells $c_2$ and $c_3$ are distinct.
- Let's denote the number of different integers in the grid by $K$; then, each of these integers should lie between $1$ and $K$ inclusive.
- $K$ should be minimum possible.
Find the minimum value of $K$ and a resulting (filled) grid. If there are multiple solutions, you may find any one.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains two space-separated integers $N$ and $M$.

-----Output-----
- For each test case, print $N+1$ lines.
- The first line should contain a single integer — the minimum $K$.
- Each of the following $N$ lines should contain $M$ space-separated integers between $1$ and $K$ inclusive. For each valid $i, j$, the $j$-th integer on the $i$-th line should denote the number in the $i$-th row and $j$-th column of the grid.

-----Constraints-----
- $1 \le T \le 500$
- $1 \le N, M \le 50$
- the sum of $N \cdot M$ over all test cases does not exceed $7 \cdot 10^5$

-----Subtasks-----
Subtask #1 (100 points): original constraints

-----Example Input-----
2
1 1
2 3

-----Example Output-----
1
1
3
1 1 2
2 3 3

-----Explanation-----
Example case 1: There is only one cell in the grid, so the only valid way to fill it is to write $1$ in this cell. Note that we cannot use any other integer than $1$.
Example case 2: For example, the integers written in the neighbours of cell $(2, 2)$ are $1$, $2$ and $3$; all these numbers are pairwise distinct and the integer written inside the cell $(2, 2)$ does not matter. Note that there are pairs of neighbouring cells with the same integer written in them, but this is OK.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '# cook your dish here\nt = int(input())\nfor _ in range(t):\n m,n = [int(d) for d in input().split()]\n\n if m == 1:\n  arr = []\n  if n%4 == 0:\n   print(2)\n   arr = [[1,1,2,2]*(n//4)]\n  elif n%4 == 1:\n   if n == 1:\n    print(1)\n    arr = [[1]]\n   else:\n    print(2)\n    arr = [[1,1,2,2]*(n//4) + [1]]\n  elif n%4 == 2:\n   if n == 2:\n    print(1)\n    arr = [[1,1]]\n   else:\n    print(2)\n    arr = [[1,1,2,2]*(n//4) + [1,1]]\n  elif n%4 == 3:\n   print(2)\n   arr = [[1,1,2,2]*(n//4) + [1,1,2]]\n\n elif m == 2:\n  if n%3 == 0:\n   print(3)\n   a1 = [1,2,3]*(n//3)\n   arr = [a1,a1]\n\n  elif n%3 == 1:\n   if n == 1:\n    print(1)\n    arr = [[1],[1]]\n   else:\n    print(3)\n    a1 = [1,2,3]*(n//3) + [1]\n    arr = [a1,a1]\n\n  elif n%3 == 2:\n   if n == 2:\n    print(2)\n    arr = [[1,2],[1,2]]\n   else:\n    print(3)\n    a1 = [1,2,3]*(n//3) + [1,2]\n    arr = [a1,a1]\n\n elif m == 3:\n  if n == 1:\n   print(2)\n   arr = [[1],[1],[2]]\n  elif n == 2:\n   print(3)\n   arr = [[1,1],[2,2],[3,3]]\n  elif n == 3:\n   print(4)\n   arr = [[1,3,4],[4,2,1],[4,2,1]]\n  elif n == 4:\n   print(4)\n   arr = [[1,3,4,2],[4,2,1,3],[4,2,1,3]]\n  else:\n   if n%4 == 0:\n    print(4)\n    a1 = [1,3,4,2]*(n//4)\n    a2 = [4,2,1,3]*(n//4)\n    arr = [a1,a2,a2]\n \n   elif n%4 == 1:\n    print(4)\n    a1 = [1,3,4,2]*(n//4) + [1]\n    a2 = [4,2,1,3]*(n//4) + [4]\n    arr = [a1,a2,a2]\n\n   elif n%4 == 2:\n    print(4)\n    a1 = [1,3,4,2]*(n//4) + [1,3]\n    a2 = [4,2,1,3]*(n//4) + [4,2]\n    arr = [a1,a2,a2]\n\n   elif n%4 == 3:\n    print(4)\n    a1 = [1,3,4,2]*(n//4) + [1,3,4]\n    a2 = [4,2,1,3]*(n//4) + [4,2,1]\n    arr = [a1,a2,a2]\n\n else:\n  if n == 1:\n   print(2)\n   a1 = [1,3,4,2]*(n//4) + [1]\n   a2 = [4,2,1,3]*(n//4) + [2]\n   arr = []\n   i = 0\n   j = 0\n   c = 0\n   c1 = 0\n   for i in range(m):\n    if j == 0 and c < 3:\n     arr.append(a1)\n     c = c + 1\n     if c == 2:\n      j = 1\n      c = 0\n    else:\n     arr.append(a2)\n     c1 = c1 + 1\n     if c1 == 2:\n      j = 0\n      c1 = 0\n  \n  elif n == 2:\n   print(3)\n   arr = []\n   a1 = [1,1]\n   a2 = [2,2]\n   a3 = [3,3]\n\n   if m%3 == 1:\n    arr = [a1,a2,a3]*(m//3) + [a1]\n   elif m%3 == 2:\n    arr = [a1,a2,a3]*(m//3) + [a1,a2]\n   elif m%3 == 0:\n    arr = [a1,a2,a3]*(m//3)\n\n  else:\n   print(4)\n   if n%4 == 0:\n    a1 = [1,3,4,2]*(n//4)\n    a2 = [4,2,1,3]*(n//4)\n    arr = []\n    i = 0\n    j = 0\n    c = 0\n    c1 = 0\n    for i in range(m):\n     if j == 0 and c < 3:\n      arr.append(a1)\n      c = c + 1\n      if c == 2:\n       j = 1\n       c = 0\n     else:\n      arr.append(a2)\n      c1 = c1 + 1\n      if c1 == 2:\n       j = 0\n       c1 = 0\n\n   elif n%4 == 1:\n    a1 = [1,3,4,2]*(n//4) + [1]\n    a2 = [4,2,1,3]*(n//4) + [4]\n    arr = []\n    i = 0\n    j = 0\n    c = 0\n    c1 = 0\n    for i in range(m):\n     if j == 0 and c < 3:\n      arr.append(a1)\n      c = c + 1\n      if c == 2:\n       j = 1\n       c = 0\n     else:\n      arr.append(a2)\n      c1 = c1 + 1\n      if c1 == 2:\n       j = 0\n       c1 = 0\n\n   elif n%4 == 2:\n\n    a1 = [1,3,4,2]*(n//4) + [1,3]\n    a2 = [4,2,1,3]*(n//4) + [4,2]\n    arr = []\n    i = 0\n    j = 0\n    c = 0\n    c1 = 0\n    for i in range(m):\n     if j == 0 and c < 3:\n      arr.append(a1)\n      c = c + 1\n      if c == 2:\n       j = 1\n       c = 0\n     else:\n      arr.append(a2)\n      c1 = c1 + 1\n      if c1 == 2:\n       j = 0\n       c1 = 0\n\n   elif n%4 == 3:\n\n    a1 = [1,3,4,2]*(n//4) + [1,3,4]\n    a2 = [4,2,1,3]*(n//4) + [4,2,1]\n    arr = []\n    i = 0\n    j = 0\n    c = 0\n    c1 = 0\n    for i in range(m):\n     if j == 0 and c < 3:\n      arr.append(a1)\n      c = c + 1\n      if c == 2:\n       j = 1\n       c = 0\n     else:\n      arr.append(a2)\n      c1 = c1 + 1\n      if c1 == 2:\n       j = 0\n       c1 = 0\n\n\n\n for i in range(m):\n  for j in range(n):\n   print(arr[i][j],end = " ")\n  print()\n\n\n\n\n    \n    \n\n\n\n\n\n\n\n\n\n\n\n\n\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16157