#include <bits/stdc++.h>
using namespace std;
const int maxn = 205000;
vector<int> side[maxn];
int col[maxn];
int a[maxn];
int mx, loc;
void dfs(int u, int fa, int dis, int last_col) {
  if (a[u] && a[u] != last_col) {
    last_col = a[u];
    dis++;
  }
  if (dis > mx) {
    mx = dis;
    loc = u;
  }
  for (int i = 0; i < side[u].size(); i++) {
    int v = side[u][i];
    if (v == fa) continue;
    dfs(v, u, dis, last_col);
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = (1), iend = (n); i <= iend; i++) cin >> a[i];
  for (int i = (1), iend = (n - 1); i <= iend; i++) {
    int u, v;
    cin >> u >> v;
    side[u].push_back(v);
    side[v].push_back(u);
  }
  mx = 0;
  dfs(1, 0, 0, 0);
  mx = 0;
  dfs(loc, 0, 0, 0);
  cout << mx / 2 + 1 << endl;
  for (int i = (1), iend = (n); i <= iend; i++) side[i].clear();
}
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
