#P13641. [NWRRC 2021] New White-Black Tree

[NWRRC 2021] New White-Black Tree

题目描述

Naomi has learnt about Red-Black trees, now it's time to learn about White-Black trees. She is reading an algorithms book. Some pages contain pictures of trees, but the edges of the trees faded out through all these years. According to the text, each of these edges should be either white or black.

Naomi noticed that each vertex has two integers written beside it. She guessed that the first integer is the number of white edges incident to the vertex, and the second is the number of black edges incident to the vertex.

Naomi recreated all the pictures. Can you do that?

输入格式

The first line contains an integer tt --- the number of pictures to recreate (1t31051 \le t \le 3 \cdot 10^5).

The following lines describe tt pictures. Each description starts with a line containing an integer nn --- the number of vertices in the tree (1n31051 \le n \le 3 \cdot 10^5).

The ii-th of the following nn lines of the picture description contains two integers wiw_i and bib_i --- two integers written beside the ii-th vertex of the tree: the number of white and black edges incident to the ii-th vertex (0wi,bin10 \le w_i, b_i \le n - 1).

It is guaranteed that the sum of nn over all the pictures does not exceed 31053 \cdot 10^5.

输出格式

Print tt blocks of output, the ii-th of which should contain the information about recreating picture ii.

In the first line of each block print No\tt{No} if there is no way, and Yes\tt{Yes} if there is at least one way to recreate the picture. If there is a way to recreate the picture of the tree, print additional n1n - 1 lines, each of them containing two integers and a letter W\tt{W} for white or B\tt{B} for black: viv_i, uiu_i and cic_i, defining an edge between vertices viv_i and uiu_i of color cic_i (1vi,uin1 \le v_i, u_i \le n; cic_i is either W\tt{W} or B\tt{B}).

If there are multiple ways to recreate a picture, you can print any of them. The edges of the tree can be printed in any order.

6
4
1 1
1 1
1 0
1 0
4
1 0
2 1
1 1
1 0
1
0 0
2
0 1
0 1
2
1 0
0 1
3
2 0
0 1
0 1
Yes
1 4 W
2 3 W
2 1 B
No
Yes
Yes
2 1 B
No
No