#include using namespace std; using ll = long long; using ld = long double; using vll = vector; using pll = pair; #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=(n)-1;0<=i;i--) #define REP(i,n) for(int i=1;i<=n;i++) #define all(a) a.begin(),a.end() #define sort(a) sort(all(a)) #define rev(a) reverse(all(a)) char el='\n'; void YN(bool f){cout<<(f?"Yes":"No")<<"\n";} template bool chmin(T& x,T y){if(x>y){x=y;return true;}return false;} template bool chmax(T& x,T y){if(x istream &operator>>(istream &is, vector &v){ for(T &in : v) is >> in; return is;} template ostream &operator<<(ostream &os, vector &v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os;} bool solve(){ int n, m, k; cin >> n >> m >> k; vector e(n); rep(i,m){ int u, v; cin >> u >> v; u--; v--; e[u].push_back(v); e[v].push_back(u); } vll a(n), b(n), cnt(n); cin >> b; rep(i,n) cnt[i] = e[i].size(); vector used(n, false); queue q; rep(i,n) if(e[i].size()==1) q.push(i); while(q.size()){ int f = q.front(); q.pop(); for(int t:e[f]) if(used[t]==false){ ll dif = (b[f]-a[f]+k)%k; a[f] = (a[f]+dif)%k; a[t] = (a[t]+dif)%k; cnt[t]--; used[f] = true; if(cnt[t]==1) q.push(t); } } return (a==b); } int main(){ int t; cin >> t; rep(i,t) YN(solve()); }