#include <bits/stdc++.h>
using namespace std;
int n, t, x, y, a[100050];
vector<int> e[100050];
void dfs(int c, int f)
{
for (int i = 0; i < e[c].size(); i++)
{
int v = e[c][i];
if (v == f)
continue;
dfs(v, c);
a[c] += a[v]; // 统计带有宝物的路径
}
}
int main()
{
cin >> t;
while (t--)
{
cin >> n;
int r = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", a + i);
if (a[i] != 0)
{
r = i; // dfs 起点
}
}
for (int i = 1; i < n; i++)
{
scanf("%d %d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
dfs(r, 0);
bool f = true; // 假设可以
// 搜索三岔路
for (int i = 1; i <= n; i++)
{
if (a[i])
{
int cnt = 0;
for (int j = 0; j < e[i].size(); j++)
{
if (a[e[i][j]])
cnt++;
if (cnt > 2) // 存在三岔路,无法获取所有宝物
{
f = false;
break;
}
}
}
if (!f)
break;
}
if (f)
cout << "Yes\n";
else
cout << "No\n";
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++)
e[i].clear();
}
return 0;
}