You are given a tree with $N$ vertices (numbered $1$ through $N$) and a bag with $N$ markers. There is an integer written on each marker; each of these integers is $0$, $1$ or $2$. You must assign exactly one marker to each vertex.
Let's define the unattractiveness of the resulting tree as the maximum absolute difference of integers written on the markers in any two vertices which are connected by an edge.
Find the minimum possible unattractiveness of the resulting tree.

-----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 line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers denoting the numbers on markers in the bag.
- Each of the next $N-1$ lines contains two space-separated integers $u$ and $v$ denoting an edge between vertices $u$ and $v$.

-----Output-----
For each test case, print a single line containing one integer — the minimum unattractiveness.

-----Constraints-----
- $1 \le T \le 30$
- $1 \le N \le 100$
- $1 \le u, v \le N$
- the graph described on the input is a tree

-----Example Input-----
3
3
0 1 1
1 2
1 3
3
0 1 2
1 2
1 3
4
2 2 2 2
1 2
1 3
3 4

-----Example Output-----
1
1
0

-----Explanation-----
Example case 1:

```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\nimport numpy as np\ntests = int(input())\nfor _ in range(tests):\n   n = int(input())\n   weights = [int(j) for j in input().split()]\n   edges = [[0] for _ in range(n-1)]\n   for i in range(n-1):\n      edges[i] = [int(j)-1 for j in input().split()]\n   vertex_set = [[] for _ in range(n)]\n   for i in range(n-1):\n      vertex_set[edges[i][0]].append(edges[i][1])\n      vertex_set[edges[i][1]].append(edges[i][0])\n   counts = [0 for _ in range(3)]\n   for i in range(n):\n      counts[weights[i]] += 1\n   if counts[1] == 0:\n      print(2 * (counts[0] != 0 and counts[2] != 0))\n   elif counts[1] == n:\n      print(0)\n   else:\n      visited = [0]\n      for i in range(n):\n         vertex = visited[i]\n         for v in vertex_set[vertex]:\n            if v not in visited:\n               visited.append(v)\n      vertex_nums = [[0] for _ in range(n)]\n      for i in range(n-1,-1,-1):\n         vertex = visited[i]\n         for v in vertex_set[vertex]:\n            if v in visited[i:]:\n               vertex_nums[vertex].append(sum(vertex_nums[v])+1)\n      for i in range(n):\n         vertex_nums[i].append(n-1-sum(vertex_nums[i]))\n      sums = np.zeros(n,dtype=bool)\n      sums[0] = True\n      for i in range(n):\n         new_sums = np.zeros(n,dtype=bool)\n         new_sums[0] = True\n         for num in vertex_nums[i]:\n            new_sums[num:n] = np.logical_or(new_sums[num:n],new_sums[:n-num])\n         sums = np.logical_or(sums,new_sums)\n      solved = False\n      for i in range(n):\n         if sums[i] and counts[0] <= i and counts[2] <= n - 1 - i:\n            solved = True\n            break\n      if solved or counts[1] > 1:\n         print(1)\n      else:\n         print(2)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 6170407