#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 1e5 + 9;
vector<int> e[N];
bool flag;
int t, n, a[N], b;
int dfs(int u, int fa) {
if (e[u].size() == 1 && e[u][0] == fa)
return a[u];
int ans = 0, p = 0;
for (auto v : e[u]) {
if (v != fa) {
int x = dfs(v, u);
if (x) {
p++;
ans += x;
}
}
}
ans += a[u];
if (p > 2 || (ans != b && p > 1))
flag = false;
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
flag = true;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
e[i].clear();
b += a[i];
}
for (int i = 1; i <= n - 1; i++) {
int x, y;
cin >> x >> y;
e[x].push_back(y);
e[y].push_back(x);
}
dfs(1, 0);
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}