#include <bits/stdc++.h>
using namespace std;
int gi() {
  char cc = getchar();
  int cn = 0, flus = 1;
  while (cc < '0' || cc > '9') {
    if (cc == '-') flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
  return cn * flus;
}
const int N = 2e5 + 5;
int n, Ans, col[N], f[N][2];
vector<int> G[N];
void add(int x, int y) { G[x].push_back(y), G[y].push_back(x); }
void dfs(int x, int fa) {
  f[x][0] = f[x][1] = 0;
  if (col[x] == 1) f[x][0] = 1;
  if (col[x] == 2) f[x][1] = 1;
  for (int v : G[x]) {
    if (v == fa) continue;
    dfs(v, x);
    for (register int i = (0); i <= (1); ++i)
      for (register int j = (0); j <= (1); ++j)
        Ans = max(Ans, f[x][i] + f[v][j] - (i == j));
    if (col[x] == 1)
      f[x][0] = max(f[x][0], max(f[v][0], f[v][1] + 1));
    else if (col[x] == 2)
      f[x][1] = max(f[x][1], max(f[v][0] + 1, f[v][1]));
    else
      for (register int i = (0); i <= (1); ++i) f[x][i] = max(f[x][i], f[v][i]);
  }
}
void solve() {
  n = gi(), Ans = 0;
  int x, y;
  for (register int i = (1); i <= (n); ++i) col[i] = gi();
  for (register int i = (2); i <= (n); ++i) x = gi(), y = gi(), add(x, y);
  dfs(1, 1);
  cout << (Ans / 2) + 1 << endl;
  for (register int i = (1); i <= (n); ++i) G[i].clear();
}
signed main() {
  int T = gi();
  while (T--) solve();
  return 0;
}
