X(or)-mas Tree

 'Twas the night before Christmas, and Santa's frantically setting up his new Christmas tree! There are 

n nodes in the tree, connected by n1 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 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 (ai,bi), 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 (1t2104) — the number of test cases. Then t cases follow.

The first line of each test case contains two integers, n and m (2n21051m2105) — the size of tree and the number of elves respectively.

The next n1 lines of each test case each contains three integers, xy, and v (1x,yn1v<230) — 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.
  • v0: The set of lights on the edge is v.

The next m lines of each test case each contains three integers, ab, and p (1a,bnab0p1) — 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 2105 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 n1 lines each containing three integers: xy, and v (1x,yn0v<230) — 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
Copy
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
Copy
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
Previous
Next Post »