#include <bits/stdc++.h>
using namespace std;
int a[400001][2], b[200001], ls[200001], T, n, i, j, k, l, len, mx, mx2;
void New(int x, int y) {
  ++len;
  a[len][0] = y;
  a[len][1] = ls[x];
  ls[x] = len;
}
void dfs(int Fa, int t, int Ls, int sum) {
  int i;
  if (sum > mx) mx = sum, mx2 = t;
  for (i = ls[t]; i; i = a[i][1])
    if (a[i][0] != Fa)
      dfs(t, a[i][0], (b[a[i][0]] > 0) ? b[a[i][0]] : Ls,
          sum + (b[a[i][0]] > 0 && b[a[i][0]] != Ls));
}
int main() {
  scanf("%d", &T);
  for (; T; --T) {
    scanf("%d", &n), len = 0, memset(ls, 0, (n + 1) * 4);
    for (i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (i = 1; i <= n - 1; i++) scanf("%d%d", &j, &k), New(j, k), New(k, j);
    mx = -1, dfs(0, 1, b[1], b[1] > 0);
    mx = -1, dfs(0, mx2, b[mx2], b[mx2] > 0);
    printf("%d\n", mx / 2 + 1);
  }
}
