An area named Renus, is divided into $(N \times M)$ cells. According to archaeological survey the area contains huge amount of treasure. Some cells out of $(N \times M)$ cells contain treasure. But problem is, you can't go to every cell as some of the cells are blocked.  
For every $a_{ij}$ cell($1 \leq i \leq N$,$1 \leq j \leq M$), your task is to find the distance of the nearest cell having treasure. 
Note:
- You can only traverse up, down, left and right from a given cell.
- Diagonal movements are not allowed.
- Cells having treasure can't be blocked, only empty cells ( cells without treasure) can be blocked.  

-----Input Format:------
- First line contains $T$, the number of test cases.
- Second line contains two space-separated integers $N\ and\ M$.
- Third line contains a single integer $X$ denoting number of cells having treasures, followed by $X$ lines containing two space-separated integers $x_i$ and $y_i$ denoting  position of row and column of $i^{th}$ treasure, for every $1\leq i \leq X$
- The next line contains a single integer $Y$ denoting the number of cells that are blocked, and it is followed by subsequent $Y$ lines containing  two space-separated integers $u_i$ and $v_i$ denoting position of row and column of blocked cells , for every $1\leq i \leq Y$

-----Constraints:------
- $1\le T \le 100$
- $1 \le N, M \le 200$
- $1 \le X < N*M$
- $0 \le Y <(N*M) - X$
- $1 \le x_i,u_j \le N, for\ every\ 1 \le i \le X\ and\ 1 \le j \le Y$
- $1 \le y_i,v_j \le M, for\ every\ 1 \le i \le X\ and\ 1 \le j \le Y$

-----Output Format:------
For each test case print a $N \times M$ matrix where each cell consists of distance of nearest treasure. Cells that are blocked will show "$X$" (without quotes). Also cells that doesn't have access to any treasure will show "$-1$" (without quotes).
Note: Co-ordinate of top left cell is $(1,1)$.

-----Sample Input-----
1
3 3
2
1 1
1 3
2
2 1
2 2

-----Sample Output-----
0 1 0 
X X 1
4 3 2

-----Explanation:-----
- Coordinates  (1,1) and (1,3)  shows "0" because they contain treasure and nearest distance is 0.
- Coordinates (2,1) and (2,2) shows "X" as they are blocked.
- Rest shows distance of nearest cell having treasure.

```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 = 't=int(input())\nfor _ in range(t):\n n,m=[int(x) for x in input().split()]\n mat=[]\n ans=[]\n for i in range(n+2):\n  l=[]\n  p=[]\n  for j in range(m+2):\n   l.append(0)\n   p.append(1000000000)\n  mat.append(l)\n  ans.append(p)\n y=int(input())\n for i in range(y):\n  a,b=[int(x) for x in input().split()]\n  mat[a][b]=1\n  ans[a][b]=0\n y=int(input())\n for i in range(y):\n  a,b=[int(x) for x in input().split()]\n  mat[a][b]=1000000000\n  ans[a][b]=1000000000\n for i in range(1,n+1):\n  for j in range(1,m+1):\n   if mat[i][j]==1 or mat[i][j]==1000000000:\n    continue\n   else:\n    ans[i][j]=min(ans[i][j],ans[i][j-1]+1,ans[i-1][j]+1)\n for i in range(n,0,-1):\n  for j in range(m,0,-1):\n   if mat[i][j] == 1 or mat[i][j] == 1000000000:\n    continue\n   else:\n    ans[i][j]=min(ans[i][j],ans[i+1][j]+1,ans[i][j+1]+1)\n for i in range(1,n+1):\n  for j in range(m, 0, -1):\n   if mat[i][j] == 1 or mat[i][j] == 1000000000:\n    continue\n   else:\n    ans[i][j] = min(ans[i][j], ans[i - 1][j] + 1, ans[i][j + 1] + 1)\n for i in range(n, 0, -1):\n  for j in range(1,m+1):\n   if mat[i][j] == 1 or mat[i][j] == 1000000000:\n    continue\n   else:\n    ans[i][j] = min(ans[i][j], ans[i + 1][j] + 1, ans[i][j - 1] + 1)\n for i in range(1,n+1):\n  for j in range(1,m+1):\n   if mat[i][j]==1 or mat[i][j]==1000000000:\n    continue\n   else:\n    ans[i][j]=min(ans[i][j],ans[i][j-1]+1,ans[i-1][j]+1)\n for i in range(n,0,-1):\n  for j in range(m,0,-1):\n   if mat[i][j] == 1 or mat[i][j] == 1000000000:\n    continue\n   else:\n    ans[i][j]=min(ans[i][j],ans[i+1][j]+1,ans[i][j+1]+1)\n for i in range(1,n+1):\n  for j in range(m, 0, -1):\n   if mat[i][j] == 1 or mat[i][j] == 1000000000:\n    continue\n   else:\n    ans[i][j] = min(ans[i][j], ans[i - 1][j] + 1, ans[i][j + 1] + 1)\n for i in range(n, 0, -1):\n  for j in range(1,m+1):\n   if mat[i][j] == 1 or mat[i][j] == 1000000000:\n    continue\n   else:\n    ans[i][j] = min(ans[i][j], ans[i + 1][j] + 1, ans[i][j - 1] + 1)\n for i in range(1,n+1):\n  for j in range(1,m+1):\n   if mat[i][j]==1000000000:\n    print(\'X\',end=" ")\n   elif ans[i][j]>=1000000000:\n    print(\'-1\',end=" ")\n   else:\n    print(ans[i][j],end=" ")\n  print()'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16069