import sys import pypyjit sys.setrecursionlimit(2 * 10**5 + 1) pypyjit.set_param("max_unroll_recursion=-1") def solve(): N, M, K = [int(s) for s in input().split()] tree = [[] for _ in range(N)] for _ in range(M): u, v = [int(s) - 1 for s in input().split()] tree[u].append(v) tree[v].append(u) B = [int(s) for s in input().split()] def dp(curr, prev): # 子の寄与 children = 0 for to in tree[curr]: if to == prev: continue children += dp(to, curr) children %= K return (children + B[curr]) % K if dp(0, -1) == 0: print("Yes") else: print("No") if __name__ == "__main__": T = int(input()) for _ in range(T): solve()