#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n,k;
cin >> n >> k;
int a[n];
int x;
int c[n+1];
for(int i=0;i<n;i++){
cin >> a[i];
c[i+1] = a[i];
if(i == 0){
x = a[i];
}
else{
x = x ^ a[i];
}
}
vector<set<int>> b(n+1);
for(int i=0;i<n-1;i++){
int y,z;
cin >> y >> z;
b[y].insert(z);
b[z].insert(y);
}
if(x == 0){
cout << "YES" << endl;
}
else{
if(k == 2){
cout << "NO" << endl;
}
else{
stack<int> st;
st.push(1);
int cnt(0);
while(st.size() > 0){
int tp = st.top();
if(b[tp].size() > 0){
int fir = *b[tp].begin();
b[fir].erase(tp);
b[tp].erase(fir);
st.push(fir);
}
else{
int s = st.top();
if(c[s] == x){
cnt++;
}
st.pop();
if(st.size() > 0){
int zz = st.top();
// cout << zz << " " << s << endl;
if(c[s] != x){
c[zz] = c[zz] ^ c[s];
}
}
}
}
if(cnt >= 2){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCB0OwoJY2luID4+IHQ7Cgl3aGlsZSh0LS0pewoJCWludCBuLGs7CgkJY2luID4+IG4gPj4gazsKCQlpbnQgYVtuXTsKCQlpbnQgeDsKCQlpbnQgY1tuKzFdOwoJCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCQljaW4gPj4gYVtpXTsKCQkJY1tpKzFdID0gYVtpXTsKCQkJaWYoaSA9PSAwKXsKCQkJCXggPSBhW2ldOwoJCQl9CgkJCWVsc2V7CgkJCQl4ID0geCBeIGFbaV07CgkJCX0KCQl9CgkJdmVjdG9yPHNldDxpbnQ+PiBiKG4rMSk7CgkJZm9yKGludCBpPTA7aTxuLTE7aSsrKXsKCQkJaW50IHksejsKCQkJY2luID4+IHkgPj4gejsKCQkJYlt5XS5pbnNlcnQoeik7Cgk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