#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { x = getchar(); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head), R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first), putchar(' '), _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head), putchar(sizeof...(tail) ? ' ' : '\n'), W(tail...);
}
}  // namespace IO
using namespace IO;
const int maxn = 2e5 + 50;
const int mod = 1e9 + 7;
long long qp(long long a, long long n) {
  long long res = 1;
  n %= mod - 1;
  if (n < 0) n += mod - 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long qp(long long a, long long n, int mod) {
  long long res = 1;
  n %= mod - 1;
  if (n < 0) n += mod - 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int n;
int b[maxn];
vector<int> edge[maxn];
int mx, mxpos;
void dfs(int u, int pre, int color, int re) {
  if (mx < re) {
    mx = re;
    mxpos = u;
  }
  for (auto v : edge[u]) {
    if (v == pre) continue;
    if (color == 0)
      dfs(v, u, b[v], re + (b[v] > 0));
    else if (b[v] == 0)
      dfs(v, u, color, re);
    else
      dfs(v, u, b[v], re + (b[v] != color));
  }
}
int main(int argc, char *argv[]) {
  int T;
  scanf("%d", &T);
  for (int kase = 1; kase <= T; ++kase) {
    R(n);
    for (int i = 1; i <= n; ++i) edge[i].clear();
    for (int i = 1; i <= n; ++i) R(b[i]);
    for (int i = 1; i < n; ++i) {
      int u, v;
      R(u, v);
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
    mx = -1;
    dfs(1, 0, b[1], b[1] > 0);
    mx = -1;
    dfs(mxpos, 0, b[mxpos], b[mxpos] > 0);
    W(mx / 2 + 1);
  }
  return 0;
}
