#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int large = 2e5 + 1;
int n;
vector<int> color;
vector<int> edges[large];
pair<int, int> dia(int node, int parent) {
  bool rg = 0;
  if (color[node] == 0) rg = 1, color[node] = color[parent];
  pair<int, int> mdepth = {1, node};
  for (auto &a : edges[node]) {
    if (parent == a) continue;
    pair<int, int> cur = dia(a, node);
    if (color[a] != color[node] && color[a] != 0) cur.first++;
    if (cur.first > mdepth.first)
      mdepth = cur;
    else if (cur.first == mdepth.first) {
      if (color[cur.second]) mdepth = cur;
    }
  }
  if (rg) color[node] = 0;
  return mdepth;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    int root = 1;
    color.resize(n + 1);
    for (int i = 1; i <= n; i++) edges[i].clear();
    for (int i = 1; i <= n; i++) cin >> color[i];
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      edges[u].push_back(v);
      edges[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
      if (color[i] != 0) root = i;
    int nroot = dia(root, 0).second;
    int diameter = dia(nroot, 0).first;
    cout << diameter / 2 + 1 << "\n";
  }
  return 0;
}
