import sys input = sys.stdin.readline T=int(input()) for tests in range(T): N,M,K=map(int,input().split()) E=[[] for i in range(N)] for i in range(M): x,y=map(int,input().split()) x-=1 y-=1 E[x].append(y) E[y].append(x) B=list(map(int,input().split())) # 木のHL分解+LCA ROOT=0 QUE=[ROOT] Parent=[-1]*N Parent[ROOT]=N # ROOTの親を定めておく. Child=[[] for i in range(N)] TOP_SORT=[] # トポロジカルソート while QUE: # トポロジカルソートと同時に親を見つける x=QUE.pop() TOP_SORT.append(x) for to in E[x]: if Parent[to]==-1: Parent[to]=x Child[x].append(to) QUE.append(to) for x in TOP_SORT[::-1]: if x==0: break if B[x]!=0: B[Parent[x]]-=B[x] B[x]=0 if B[0]%K==0: print("Yes") else: print("No")