#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, nex;
} ed[400005];
int h[200005], cnt, col[200005], maxi, poz;
void added(int x, int y) {
  ed[++cnt] = {y, h[x]};
  h[x] = cnt;
  ed[++cnt] = {x, h[y]};
  h[y] = cnt;
}
void dfs(int nod, int t, int dist, int nr) {
  if (col[nod] && col[nod] != nr) dist++, nr = col[nod];
  if (dist > maxi) maxi = dist, poz = nod;
  int i;
  for (i = h[nod]; i; i = ed[i].nex)
    if (ed[i].to != t) dfs(ed[i].to, nod, dist, nr);
}
int main() {
  int t, i1;
  scanf("%d", &t);
  for (i1 = 1; i1 <= t; i1++) {
    int n;
    scanf("%d", &n);
    cnt = 0;
    int i;
    for (i = 1; i <= n; i++) h[i] = 0;
    for (i = 1; i <= n; i++) scanf("%d", &col[i]);
    int a, b;
    for (i = 1; i < n; i++) {
      scanf("%d%d", &a, &b);
      added(a, b);
    }
    maxi = -1;
    dfs(1, 0, 0, 0);
    maxi = -1;
    dfs(poz, 0, 0, 0);
    printf("%d\n", maxi / 2 + 1);
  }
  return 0;
}
