#include <bits/stdc++.h>
using pii = std::pair<int, int>;
const int N = 2e5 + 10, inf = 1073741823;
inline int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int tot = 1, fir[N], nex[N * 2], got[N * 2];
inline void add(int u, int v) {
  nex[++tot] = fir[u], fir[u] = tot, got[tot] = v;
  nex[++tot] = fir[v], fir[v] = tot, got[tot] = u;
}
int col[N], ans;
struct node {
  pii a, b;
} f[N][2];
inline void upd(node &a, pii dat) {
  if (a.a.second == dat.second)
    a.a = std::max(a.a, dat);
  else if (dat > a.a)
    a.b = a.a, a.a = dat;
  else if (a.a.second != dat.second)
    a.b = std::max(a.b, dat);
}
inline void dfs(int u, int fa) {
  f[u][0] = f[u][1] = node{pii(0, 0), pii(0, 0)};
  for (int i = fir[u]; i; i = nex[i]) {
    if (got[i] == fa) continue;
    dfs(got[i], u);
    if (col[u] != 2) {
      pii w = pii(inf, 0);
      if (col[got[i]] != 2) w = std::min(w, pii(f[got[i]][0].a.first, got[i]));
      if (col[got[i]] != 1)
        w = std::min(w, pii(f[got[i]][1].a.first + 1, got[i]));
      upd(f[u][0], w);
    }
    if (col[u] != 1) {
      pii w = pii(inf, 0);
      if (col[got[i]] != 2)
        w = std::min(w, pii(f[got[i]][0].a.first + 1, got[i]));
      if (col[got[i]] != 1) w = std::min(w, pii(f[got[i]][1].a.first, got[i]));
      upd(f[u][1], w);
    }
  }
  int w = inf;
  if (col[u] != 1) w = std::min(w, f[u][1].a.first + f[u][1].b.first);
  if (col[u] != 2) w = std::min(w, f[u][0].a.first + f[u][0].b.first);
  ans = std::max(ans, w);
}
int main() {
  for (int T = read(); T; --T) {
    int n = read();
    ans = 0, tot = 1;
    for (int i = 1; i <= n; ++i) fir[i] = 0;
    for (int i = 1; i <= n; ++i) col[i] = read();
    for (int i = 2; i <= n; ++i) add(read(), read());
    dfs(1, 0);
    printf("%d\n", (ans + 1) / 2 + 1);
  }
  return 0;
}
