#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N,M,K; cin >> N >> M >> K; vector> Graph(N); for(int i=0; i> u >> v; u--; v--; Graph.at(u).push_back(v); Graph.at(v).push_back(u); } vector B(N),A(N); for(auto &b : B) cin >> b; auto dfs = [&](auto dfs,int pos,int back) -> void { long long sum = 0; for(auto to : Graph.at(pos)){ if(to == back) continue; dfs(dfs,to,pos); int ope = (B.at(to)-A.at(to)+K)%K; A.at(to) = B.at(to),sum += ope; } A.at(pos) = sum%K; }; dfs(dfs,0,-1); if(A == B) cout << "Yes\n"; else cout << "No\n"; } }