#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m, res;
struct edge {
  int to, nxt;
} e[200005 << 1];
int tot, head[200005];
inline void adde(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
int a[200005], f[200005][3], g[200005][3];
void dfs(int u, int pa) {
  int c = a[u];
  if (c)
    f[u][c ^ 3] = g[u][c ^ 3] = 0x3f3f3f3f, f[u][c] = 0, g[u][c] = -0x3f3f3f3f;
  else
    f[u][1] = f[u][2] = 0, g[u][1] = g[u][2] = -0x3f3f3f3f;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    dfs(v, u);
    for (register int j = (1); j <= (2); ++j) {
      if (c + j == 3) continue;
      int tf = 0x3f3f3f3f, tg = 0x3f3f3f3f;
      for (register int k = (1); k <= (2); ++k) {
        if (f[v][k] == 0x3f3f3f3f) continue;
        tf = min(tf, f[v][k] + (j != k));
        tg = min(tg, f[u][j] + f[v][k] + (j != k));
      }
      f[u][j] = max(f[u][j], tf);
      g[u][j] = max(g[u][j], tg);
    }
  }
  res = max(res, min(g[u][1], g[u][2]));
}
void work() {
  n = read();
  tot = 1;
  for (register int i = (1); i <= (n); ++i) head[i] = 0, a[i] = read();
  for (register int i = (2); i <= (n); ++i) {
    int u = read(), v = read();
    adde(u, v), adde(v, u);
  }
  res = 0;
  dfs(1, 0);
  printf("%d\n", (res + 1) / 2 + 1);
}
signed main() {
  int T = read();
  while (T--) work();
  return 0;
}
