#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> adj[200005];
long long a[200005];
long long ans = 0;
long long dp[200005][2];
void dfs(long long u, long long p) {
  long long mx0 = 0, mx1 = 0;
  for (auto v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    ans = max(ans, dp[v][0] + mx1);
    ans = max(ans, dp[v][1] + mx0);
    if (a[u] == 1)
      ans = max(ans, dp[v][0] + mx0 + 1);
    else if (a[u] == 0)
      ans = max(ans, dp[v][1] + mx1 + 1);
    mx0 = max(mx0, dp[v][0]);
    mx1 = max(mx1, dp[v][1]);
  }
  dp[u][1] = mx1, dp[u][0] = mx0;
  if (a[u] == 1)
    dp[u][1] = max(dp[u][1], mx0 + 1);
  else if (a[u] == 0)
    dp[u][0] = max(dp[u][0], mx1 + 1);
}
void solve() {
  long long n;
  cin >> n;
  ans = 0;
  for (long long i = 1; i <= n; i++) {
    adj[i].clear();
    dp[i][0] = dp[i][1] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      a[i] = 2;
    else
      a[i]--;
  }
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  dfs(1, 0);
  cout << ans / 2 + 1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
}
