#include using namespace std; using ll = long long; #define all(a) a.begin(),a.end() #define reps(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) reps(i, 0, n) #define rreps(i, a, n) for (int i = (a); i > (int)(n); i--) const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; ll myceil(ll a, ll b) {return (a+b-1)/b;} template using vc = vector; template using vv = vc>; template using vvv = vv>; using pii = pair; using pll = pair; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define debug(var) do { cout << #var << " :\n"; view(var); } while(0) templatevoid view(const T& e) {cout << e;} templatevoid view(const pair& p) {cout << "{" << p.first << ", " << p.second << "}";} templatevoid view(const vc& v) {for (const auto& e : v) {view(e);cout << " ";} cout << endl;} templatevoid view(const vv& vv) {for (const auto& v : vv) {view(v);} cout << endl;} templatevoid view(const set& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const multiset& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const unordered_set& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const unordered_multiset& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const map& mp){for (const auto& e : mp) {view(e);cout << " ";} cout << endl;} // # pragma GCC target("avx2") // # pragma GCC optimize("O3") // # pragma GCC optimize("unroll-loops") // #include // using namespace atcoder; void solve() { ll n,m,k; cin >> n >> m >> k; vector u(m), v(m); rep(i,m) { cin >> u[i] >> v[i]; u[i]--; v[i]--; } vector b(n); rep(i,n) cin >> b[i]; vector> g(n); rep(i,m) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } ll even = 0; ll odd = 0; queue> que; que.push({0,0}); vector visit(n,-1); visit[0] = 1; while (!que.empty()) { auto [p,q] = que.front(); que.pop(); if (q%2) { even += b[p]; } else { odd += b[p]; } for (auto x : g[p]) { if (visit[x] < 0) { visit[x] = 1; que.push({x,q+1}); } } } if (odd%k == even%k) { cout << "Yes" << endl; } else { cout << "No" << endl; } return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t = 1; cin >> t; rep(i,t) solve(); return 0; }