#include <bits/stdc++.h>
using namespace std;
const int N = 300010, M = 600010, INF = 1e9 + 7;
int n, t, h[N], a[N], tot;
int f[N][3], g[N][3], ans;
struct edge {
  int to, nxt;
} e[M];
inline int read() {
  int ret = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret;
}
inline void add(int a, int b) {
  e[++tot].to = b;
  e[tot].nxt = h[a];
  h[a] = tot;
}
void dfs(int x, int lst) {
  int col = a[x];
  if (col)
    f[x][col ^ 3] = g[x][col ^ 3] = INF, f[x][col] = 0, g[x][col] = -INF;
  else
    f[x][1] = f[x][2] = 0, g[x][1] = g[x][2] = -INF;
  for (int i = h[x], v; v = e[i].to, i; i = e[i].nxt) {
    if (v == lst) continue;
    dfs(v, x);
    for (int j = 1; j <= 2; j++) {
      if (col + j == 3) continue;
      int tf = INF, tg = INF;
      for (int k = 1; k <= 2; k++) {
        if (f[v][k] == INF) continue;
        tf = min(tf, f[v][k] + (k != j));
        tg = min(tg, f[v][k] + f[x][j] + (k != j));
      }
      f[x][j] = max(f[x][j], tf);
      g[x][j] = max(g[x][j], tg);
    }
  }
  ans = max(ans, min(g[x][1], g[x][2]));
}
int main() {
  t = read();
  while (t--) {
    n = read();
    for (int i = 1; i <= n; i++) h[i] = 0, a[i] = read();
    for (int i = 1, a, b; i < n; i++) {
      a = read();
      b = read();
      add(a, b);
      add(b, a);
    }
    ans = 0;
    dfs(1, 1);
    printf("%d\n", (ans + 1) / 2 + 1);
  }
  return 0;
}
