#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int inf = 0x3f3f3f3f;
int a[N], f[N][3], g[N][3], ea[N << 1], eb[N << 1], ec[N], etot;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return x * f;
}
void addEdge(int x, int y) {
  etot++;
  ea[etot] = y;
  eb[etot] = ec[x];
  ec[x] = etot;
}
int res;
void dfs(int x, int fa) {
  int z = a[x];
  if (z) {
    f[x][z ^ 3] = g[x][z ^ 3] = inf;
    f[x][z] = 0;
    g[x][z] = -inf;
  } else {
    f[x][1] = f[x][2] = 0;
    g[x][1] = g[x][2] = -inf;
  }
  for (int i = ec[x]; i; i = eb[i]) {
    int y = ea[i];
    if (y == fa) continue;
    dfs(y, x);
    for (int j = 1; j <= 2; ++j) {
      if (z + j == 3) continue;
      int minf = inf, ming = inf;
      for (int k = 1; k <= 2; ++k) {
        if (f[y][k] == inf) continue;
        minf = min(minf, f[y][k] + (j != k));
        ming = min(ming, f[x][j] + f[y][k] + (j != k));
      }
      f[x][j] = max(f[x][j], minf);
      g[x][j] = max(g[x][j], ming);
    }
  }
  res = max(res, min(g[x][1], g[x][2]));
}
signed main() {
  int T = read();
  while (T-- > 0) {
    int n = read();
    for (int i = 1; i <= n; ++i) ec[i] = 0;
    etot = 0;
    for (int i = 1; i <= n; ++i) a[i] = read();
    for (int i = 2; i <= n; ++i) {
      int x = read(), y = read();
      addEdge(x, y);
      addEdge(y, x);
    }
    res = 0;
    dfs(1, 0);
    printf("%d\n", (res + 1) / 2 + 1);
  }
  return 0;
}
