Troubadour_Ggmz and Fengmi123 are playing a special UNO game. UNO cards have four colors: red, yellow, green, and blue, denoted by R, Y, G, and B, respectively. Each color contains $$$n$$$ cards, with ranks being any integers from $$$1$$$ to $$$n$$$; there may be two cards with the same color and rank. The whole deck has $$$4n$$$ cards.
At the beginning of the game, Troubadour_Ggmz arranges all $$$4n$$$ cards in a row, then Fengmi123 can perform the following operation any number of times: choose two adjacent cards, and if they are the same color or the same rank, swap their positions.
The goal of the game is to rearrange all cards into a state that is both color-ordered and rank-ordered, i.e.:
Fengmi123 wants to know whether she can achieve the target state through a sequence of allowed operations (possibly zero).
There are multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$), the number of test cases. For each test case:
The first line contains a positive integer $$$n$$$ ($$$1 \le n \le 1000$$$).
Then $$$4n$$$ lines follow, each containing a positive integer $$$x_i$$$ and a character $$$c_i$$$, where $$$1 \le x_i \le n$$$, $$$c_i \in \{\texttt{R}, \texttt{Y}, \texttt{G}, \texttt{B}\}$$$, indicating the rank and color of the $$$i$$$-th card in order. It is guaranteed that each color appears exactly $$$n$$$ times, but cards with the same color and rank may appear multiple times.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.
For each test case, if the target state can be reached, output a line containing "YES", otherwise output a line containing "NO".
You may output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as positive responses.
221 R2 Y2 R1 G1 Y2 B2 G1 B21 R2 Y1 Y2 B2 R1 G2 G1 B
YESNO