You are given a tree with each vertex coloured white, black or grey. You can remove elements from the tree by selecting a subset of vertices in a single connected component and removing them and their adjacent edges from the graph. The only restriction is that you are not allowed to select a subset containing a white and a black vertex at once.

What is the minimum number of removals necessary to remove all vertices from the tree?

Input

Each test contains multiple test cases. The first line contains an integer t (1 ≤ t ≤ 100 000), denoting the number of test cases, followed by a description of the test cases.

The first line of each test case contains an integer n (1 ≤ n ≤ 200 000): the number of vertices in the tree.

The second line of each test case contains n integers a_v (0 ≤ a_v ≤ 2): colours of vertices. Gray vertices have a_v=0, white have a_v=1, black have a_v=2.

Each of the next n-1 lines contains two integers u, v (1 ≤ u, v ≤ n): tree edges.

The sum of all n throughout the test is guaranteed to not exceed 200 000.

Output

For each test case, print one integer: the minimum number of operations to solve the problem.

Example

Input


4
2
1 1
1 2
4
1 2 1 2
1 2
2 3
3 4
5
1 1 0 1 2
1 2
2 3
3 4
3 5
8
1 2 1 2 2 2 1 2
1 3
2 3
3 4
4 5
5 6
5 7
5 8


Output


1
3
2
3

Note

<image>

In the first test case, both vertices are white, so you can remove them at the same time.

<image>

In the second test case, three operations are enough. First, we need to remove both black vertices (2 and 4), then separately remove vertices 1 and 3. We can't remove them together because they end up in different connectivity components after vertex 2 is removed.

<image>

In the third test case, we can remove vertices 1, 2, 3, 4 at the same time, because three of them are white and one is grey. After that, we can remove vertex 5.

<image>

In the fourth test case, three operations are enough. One of the ways to solve the problem is to remove all black vertices at once, then remove white vertex 7, and finally, remove connected white vertices 1 and 3.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int n;
int c[MAXN];
int d[MAXN];
bool z[MAXN];
vector<int> x[MAXN];
int dfs(int cur) {
  int ans = 0;
  queue<int> q[2];
  for (int i = 1; i <= n; ++i) {
    if (d[i] == 1) {
      z[i] = true;
      if (c[i] != 1 - cur) {
        q[cur].push(i);
      } else {
        q[cur ^ 1].push(i);
      }
    }
  }
  while (!q[cur].empty() || !q[cur ^ 1].empty()) {
    while (!q[cur].empty()) {
      int a = q[cur].front();
      q[cur].pop();
      for (int b : x[a]) {
        --d[b];
        if (z[b] || d[b] > 1) continue;
        z[b] = true;
        if (c[b] != 1 - cur) {
          q[cur].push(b);
        } else {
          q[cur ^ 1].push(b);
        }
      }
    }
    ++ans;
    cur ^= 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int times;
  cin >> times;
  while (times--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      x[i].clear();
      d[i] = 0;
      z[i] = false;
      cin >> c[i];
      if (c[i] == 0) {
        c[i] = 2;
      } else {
        --c[i];
      }
    }
    for (int i = 1; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      x[a].push_back(b);
      x[b].push_back(a);
      ++d[a];
      ++d[b];
    }
    int ans = dfs(0);
    for (int i = 1; i <= n; ++i) {
      d[i] = x[i].size();
      z[i] = false;
    }
    ans = min(ans, dfs(1));
    cout << ans << endl;
  }
  return 0;
}
