human
'Twas the night before Christmas, and Santa's frantically setting up his new Christmas tree! There are n nodes in the tree, connected by n-1 edges. On each edge of the tree, there's a set of Christmas lights, which can be represented by an integer in binary representation.


He has m elves come over and admire his tree. Each elf is assigned two nodes, a and b, and that elf looks at all lights on the simple path between the two nodes. After this, the elf's favorite number becomes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of the values of the lights on the edges in that path.

However, the North Pole has been recovering from a nasty bout of flu. Because of this, Santa forgot some of the configurations of lights he had put on the tree, and he has already left the North Pole! Fortunately, the elves came to the rescue, and each one told Santa what pair of nodes he was assigned (a_i, b_i), as well as the parity of the number of set bits in his favorite number. In other words, he remembers whether the number of 1's when his favorite number is written in binary is odd or even.

Help Santa determine if it's possible that the memories are consistent, and if it is, remember what his tree looked like, and maybe you'll go down in history!

Input

The first line contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t cases follow.

The first line of each test case contains two integers, n and m (2 ≤ n ≤ 2 ⋅ 10^5.
1 ≤ m ≤ 2 ⋅ 10^5) — the size of tree and the number of elves respectively.

The next n-1 lines of each test case each contains three integers, x, y, and v (1 ≤ x, y ≤ n.
-1 ≤ v < 2^{30}) — meaning that there's an edge between nodes x and y. If 

  * v = -1: Santa doesn't remember what the set of lights were on for this edge. 
  * v ≥ 0: The set of lights on the edge is v. 


The next m lines of each test case each contains three integers, a, b, and p (1 ≤ a, b ≤ n.
a ≠ b.
0 ≤ p ≤ 1) — the nodes that the elf was assigned to, and the parity of the number of...
impor
=====
Give me a Python program to determine if it's possible that the memories are consistent, and if it is, remember what his tree looked like, and maybe you'll go down in history!?
assistant
#Here is Python program to determine if it's possible that the memories are consistent, and if it is, remember what his tree looked like, and maybe you'll go down in history!
.
t sys
import math
from collections import deque,Counter
from sys import stdin

#sys.setrecursionlimit(10**7)

int1=lambda x: int(x)-1
stinput=lambda :stdin.readline()[:-1]
ii=lambda :int(stinput())
mi=lambda :map(int, stdin.readline().split())
li=lambda :list(mi())
mi1=lambda :map(int1, stdin.readline().split())
li1=lambda :list(mi1())
mis=lambda :map(str, stdin.readline().split())
lis=lambda :list(mis())

from collections import defaultdict
#d=defaultdict(int)
#d=defaultdict(lambda:1)

import heapq
#heapq.heapify(hq)
#heapq.heappop(hq)
#heapq.heappush(hq,1)

mod=10**9+7
Mod=998244353
INF=10**18
ans=0

def main():
  def solve(n,edge):
    seen=[-1]*n
    for i in range(n):
      if seen[i]==-1:
        d=[i]
        seen[i]=0
        while d:
          x=d.pop()
          #print(x,seen[x])
          for v,w in edge[x]:
            if seen[v]==-1:
              seen[v]=(seen[x]+w)%2
              d.append(v)
            else:
              if (seen[v]+seen[x])%2!=w:
                return False
    return seen

  t=ii()
  ANS=[]
  for _ in range(t):
    n,m=mi()
    edge=[[] for i in range(n)]
    tree=[]
    for i in range(n-1):
      a,b,c=mi()
      a,b=a-1,b-1
      tree.append((a,b,c))
      if c!=-1:
        w=0
        while c!=0:
          w+=c%2
          c//=2
        edge[a].append((b,w%2))
        edge[b].append((a,w%2))
    for i in range(m):
      a,b,c=mi()
      a,b=a-1,b-1
      edge[a].append((b,c))
      edge[b].append((a,c))
    ans=solve(n,edge)
    if ans:
      print('YES')
      for a,b,c in tree:
        if c!=-1:
          print(f'{a+1} {b+1} {c}')
        else:
          print(f'{a+1} {b+1} {(ans[a]+ans[b])%2}')
    else:
      print('NO')

if __name__ == "__main__":
  main()