#include <bits/stdc++.h>
inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x;
}
template <typename _Tp>
inline int chkmax(_Tp &x, _Tp y) {
  return x < y ? x = y, 1 : 0;
}
int n, a[200010], ans, rt, col;
std::vector<int> E[200010];
void dfs(int u, int fa, int now, int dis) {
  if (!col || chkmax(ans, dis)) rt = u, col = now;
  for (int v : E[u])
    if (v != fa) {
      dfs(v, u, a[v] ? a[v] : now, dis + ((now ^ a[v]) == 3));
    }
}
void work() {
  n = read();
  ans = -1, col = 0;
  for (int i = (1), ed_i = (n); i <= ed_i; ++i) a[i] = read(), E[i].clear();
  for (int i = (1), ed_i = (n - 1); i <= ed_i; ++i) {
    int u = read(), v = read();
    E[u].emplace_back(v), E[v].emplace_back(u);
  }
  dfs(1, 0, a[1], 0);
  dfs(rt, 0, col, 0);
  printf("%d\n", (ans + 3) >> 1);
}
int main() {
  for (int o = (1), ed_o = (read()); o <= ed_o; ++o) work();
}
