from collections import deque import sys sys.setrecursionlimit(1000000) def dfs(i,j): Pa[i] = j if i!=1 and len(G[i])==1: Leaf.append(i) return for k in G[i]: if k==j:continue dfs(k,i) T = int(input()) for _ in range(T): N,M,K = map(int,input().split()) G = {i:[] for i in range(1,N+1)} for _ in range(M): u,v = map(int,input().split()) G[u].append(v) G[v].append(u) Pa = [0]*(N+1) Leaf = deque([]) dfs(1,0) B = [0]+list(map(int,input().split())) Deg = [0]+[len(G[u])-1 for u in range(1,N+1)] Deg[1] += 1 while Leaf: u = Leaf.popleft() v = Pa[u] B[v] = (B[v]-B[u])%K Deg[v] -= 1 if Deg[v]==0: Leaf.append(v) if B[1]==0: print("Yes") else: print("No")