'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.

<image>

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 set bits in the elf's favorite number.

It is guaranteed that the sum of all n and the sum of all m don't exceed 2 ⋅ 10^5 each.

It is guaranteed that the given edges form a tree.

Output

For each test case, first print either YES or NO (in any case), whether there's a tree consistent with Santa's memory or not. 

If the answer is YES, print n-1 lines each containing three integers: x, y, and v (1 ≤ x, y ≤ n; 0 ≤ v < 2^{30}) — the edge and the integer on that edge. The set of edges must be the same as in the input, and if the value of some edge was specified earlier, it can not change. You can print the edges in any order.

If there are multiple answers, print any.

Example

Input


4
6 5
1 2 -1
1 3 1
4 2 7
6 3 0
2 5 -1
2 3 1
2 5 0
5 6 1
6 1 1
4 5 1
5 3
1 2 -1
1 3 -1
1 4 1
4 5 -1
2 4 0
3 4 1
2 3 1
3 3
1 2 -1
1 3 -1
1 2 0
1 3 1
2 3 0
2 1
1 2 1
1 2 0


Output


YES
1 2 0
1 3 1
2 4 7
3 6 0
2 5 0
YES
1 2 1
1 3 0
1 4 1
4 5 1
NO
NO

Note

The first test case is the image in the statement.

One possible answer is assigning the value of the edge (1, 2) to 5, and the value of the edge (2, 5) to 3. This is correct because: 

  * The first elf goes from node 2 to node 3. This elf's favorite number is 4, so he remembers the value 1 (as 4 has an odd number of 1 bits in its binary representation). 
  * The second elf goes from node 2 to node 5. This elf's favorite number is 3, so he remembers the value 0 (as 3 has an even number of 1 bits in its binary representation). 
  * The third elf goes from node 5 to node 6. This elf's favorite number is 7, so he remembers the value 1 (as 7 has an odd number of 1 bits in its binary representation). 
  * The fourth elf goes from node 6 to node 1. This elf's favorite number is 1, so he remembers the value 1 (as 1 has an odd number of 1 bits in its binary representation). 
  * The fifth elf goes from node 4 to node 5. This elf's favorite number is 4, so he remembers the number 1 (as 4 has an odd number of 1 bits in its binary representation). 



Note that there are other possible answers.

Difficulty: HARD
Tags: Bit manipulation

Graph algorithms

Graph traversal

Tree algorithms

Spanning trees
Skill types: Bit manipulation

Starter code:

Solutions:
def getParity(x):
	par = 0
	while x > 0:
		par += x % 2
		par %= 2
		x //= 2
	return par

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, m) = readIntArr()
		adj1 = [[] for __ in range(n)]
		edges = [-1] * (n - 1)
		adj2 = [[] for __ in range(n)]
		for i in range(n - 1):
			(u, v, val) = readIntArr()
			u -= 1
			v -= 1
			adj1[u].append((v, val))
			adj1[v].append((u, val))
			edges[i] = [u, v, val]
			if val != -1:
				adj2[u].append((v, val))
				adj2[v].append((u, val))
		for __ in range(m):
			(u, v, val) = readIntArr()
			u -= 1
			v -= 1
			adj2[u].append((v, val))
			adj2[v].append((u, val))
		nodePar = [-1] * n
		isConsistent = True
		for u in range(n):
			if nodePar[u] != -1:
				continue
			nodePar[u] = 0
			st = [(u, 0)]
			while st:
				(u, par) = st.pop()
				for (v, val) in adj2[u]:
					newPar = (par + getParity(val)) % 2
					if nodePar[v] == -1:
						nodePar[v] = newPar
						st.append((v, newPar))
					elif nodePar[v] != newPar:
						isConsistent = False
						break
				if not isConsistent:
					break
			if not isConsistent:
				break
		if not isConsistent:
			allans.append(['NO'])
			continue
		allans.append(['YES'])
		for i in range(n - 1):
			(u, v, val) = edges[i]
			if nodePar[u] == nodePar[v]:
				if val != -1:
					assert getParity(val) == 0
				if val == -1:
					edges[i][2] = 0
			else:
				if val != -1:
					assert getParity(val) == 1
				if val == -1:
					edges[i][2] = 1
			allans.append((u + 1, v + 1, edges[i][2]))
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(a, b, c):
	print('? {} {} {}'.format(a, b, c))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ansArr):
	print('! {}'.format(' '.join([str(x) for x in ansArr])))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
import math
for _abc in range(1):
	main()


import sys
I = lambda : [*map(int, sys.stdin.readline().split())]
prin = sys.stdout.write
(t,) = I()
for _ in range(t):
	(n, m) = I()
	edges = []
	same = {i: [] for i in range(n)}
	diff = {i: [] for i in range(n)}
	for i in range(n - 1):
		(x, y, v) = I()
		edges.append((x, y, v))
		if v >= 0:
			par = bin(v)[2:].count('1') % 2
			if par == 0:
				same[x - 1].append(y - 1)
				same[y - 1].append(x - 1)
			else:
				diff[x - 1].append(y - 1)
				diff[y - 1].append(x - 1)
	for i in range(m):
		(a, b, p) = I()
		if p == 0:
			same[a - 1].append(b - 1)
			same[b - 1].append(a - 1)
		else:
			diff[a - 1].append(b - 1)
			diff[b - 1].append(a - 1)
	covered = [-1] * n
	bad = False
	for i in range(n):
		if covered[i] == -1 and (not bad):
			layer = [i]
			covered[i] = 0
			while layer != [] and (not bad):
				newlayer = []
				for guy in layer:
					x = covered[guy]
					for boi in same[guy]:
						if covered[boi] == 1 - x:
							bad = True
						elif covered[boi] == -1:
							covered[boi] = x
							newlayer.append(boi)
					for boi in diff[guy]:
						if covered[boi] == x:
							bad = True
						elif covered[boi] == -1:
							covered[boi] = 1 - x
							newlayer.append(boi)
				layer = newlayer
	if bad:
		prin('NO\n')
	else:
		prin('YES\n')
		for (x, y, v) in edges:
			if v >= 0:
				prin(' '.join([str(x), str(y), str(v)]) + '\n')
			elif covered[x - 1] == covered[y - 1]:
				prin(' '.join([str(x), str(y), '0']) + '\n')
			else:
				prin(' '.join([str(x), str(y), '1']) + '\n')


import sys
import math
from collections import deque, Counter
from sys import stdin
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
import heapq
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()
					for (v, w) in edge[x]:
						if seen[v] == -1:
							seen[v] = (seen[x] + w) % 2
							d.append(v)
						elif (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(a + 1, b + 1, c)
				else:
					print(a + 1, b + 1, (ans[a] + ans[b]) % 2)
		else:
			print('NO')
main()


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque
LANS = []
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	EDGE = [list(map(int, input().split())) for i in range(n - 1)]
	ELF = [list(map(int, input().split())) for i in range(m)]
	E = [[] for i in range(n + 1)]
	NODES = [-1] * (n + 1)
	NODES[1] = 0
	for (x, y, c) in EDGE:
		if c != -1:
			sc = 0
			while c != 0:
				if c % 2 == 1:
					sc += 1
				c //= 2
			c = sc % 2
		E[x].append((y, c))
		E[y].append((x, c))
	for (x, y, c) in ELF:
		E[x].append((y, c))
		E[y].append((x, c))
	Q = deque([1])
	flag = 1
	while Q and flag == 1:
		x = Q.popleft()
		if NODES[x] == -1:
			NODES[x] = 1
		for (to, c) in E[x]:
			if c != -1:
				if NODES[to] == -1:
					NODES[to] = NODES[x] ^ c
					Q.appendleft(to)
				elif NODES[to] == NODES[x] ^ c:
					True
				else:
					flag = 0
					break
			elif NODES[to] == -1:
				Q.append(to)
	if flag == 0:
		LANS.append('NO')
		continue
	LANS.append('YES')
	for (x, y, c) in EDGE:
		if c != -1:
			LANS.append(str(x) + ' ' + str(y) + ' ' + str(c))
		elif (NODES[x] ^ NODES[y]) % 2 == 0:
			LANS.append(str(x) + ' ' + str(y) + ' 0')
		else:
			LANS.append(str(x) + ' ' + str(y) + ' 1')
sys.stdout.write('\n'.join(LANS))


from sys import stdin, stdout
from collections import deque

def parity(n):
	parity = 0
	while n:
		parity = 1 - parity
		n = n & n - 1
	return parity
t = int(stdin.readline())
for _ in range(t):
	(n, m) = [int(x) for x in stdin.readline().split()]
	edges = []
	fake_edges = {i: [] for i in range(n)}
	possible = True
	for bar in range(n - 1):
		(x, y, v) = [int(z) for z in stdin.readline().split()]
		x -= 1
		y -= 1
		edges.append((x, y, v))
		if v >= 0:
			p = parity(v)
			fake_edges[x].append((y, p))
			fake_edges[y].append((x, p))
	for bar in range(m):
		(x, y, v) = [int(z) for z in stdin.readline().split()]
		x -= 1
		y -= 1
		fake_edges[x].append((y, v))
		fake_edges[y].append((x, v))
	r_values = [-1] * n
	touched = [False] * n
	for i in range(n):
		if not possible:
			break
		if not touched[i]:
			queue = deque()
			queue.append(i)
			r_values[i] = 0
			touched[i] = True
			while len(queue) > 0:
				if not possible:
					break
				v = queue.popleft()
				for (w, p) in fake_edges[v]:
					if r_values[w] == -1:
						r_values[w] = r_values[v] ^ p
						touched[w] = True
						queue.append(w)
					elif r_values[w] != r_values[v] ^ p:
						possible = False
						break
	if possible:
		stdout.write('YES\n')
		for (v, w, new_temp) in edges:
			if new_temp == -1:
				new_temp = r_values[v] ^ r_values[w]
			stdout.write('{} {} {}\n'.format(v + 1, w + 1, new_temp))
	else:
		stdout.write('NO\n')