T = int(input()) for _ in range(T): N,M,K = list(map(int,input().split())) edge = [set() for _ in range(N)] for _ in range(M): u,v = list(map(int,input().split())) u -= 1;v -= 1 edge[u].add(v) edge[v].add(u) B = list(map(int,input().split())) leaf = [i for i in range(N) if len(edge[i]) == 1] while(leaf): a = leaf.pop() if(not edge[a]):continue b = edge[a].pop() edge[b].remove(a) B[b] = (B[b] - B[a]) % K B[a] = 0 if(len(edge[b]) == 1):leaf.append(b) print("Yes" if B == [0] * N else "No")