Drawing Lines
시간 제한2초메모리 제한2048 MB
좌표가 모두 다른 N개의 점이 각각 수직 또는 수평 방향을 가질 때, 광선들이 서로 만나지 않도록 방향을 정하는 경우의 수를 구한다.
문제
Busy Beaver likes to draw lines on paper. However, he gets sad when two lines intersect. One night, he dreamed of a masterpiece drawing consisting of many rays with no intersections. But, when he woke up, he only remembered where the rays started, and not which direction they went in! Help him recreate the drawing.
Formally, you are given points on the plane, each with distinct integer and coordinates in the range . Each point is labeled with either \tt{UD} or \tt{LR}. For each \tt{UD} point, you must draw an infinitely long ray starting at that point that goes vertically either up or down. Likewise, for each \tt{LR} point, you must draw an infinitely long ray starting at that point that goes horizontally either left or right.
Out of all ways to assign directions to each point, figure out whether there is an assignment where no two rays intersect, and if one exists, output the number of satisfying assignments, modulo .
For your convenience, we promise that if is the number of satisfying assignments and , then .
입력
Each test contains multiple test cases. The first line of input contains a single integer , the number of test cases.
The first line of each test case contains a positive integer (, representing the number of points.
The -th of the next lines contain two integers and a string , where denotes the location of the -th point, and denotes the allowed ray directions from the point.
are guaranteed to be pairwise distinct integers in the range , and the same holds for .
You are guaranteed that the sum of over all test cases is at most .
출력
For each of the test cases, output two lines.
On the first line, output "YES" or "NO", representing whether a satisfying assignment exists. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
On the second line, output the number of satisfying assignments, modulo .
힌트
In the first test case, any of the assignments results in no intersections.
In the second test case, if the first point is assigned D and the second point is assigned L, there is an intersection of the two rays at . All other assignments work.
In the third test case, all assignments result in at least one intersection.
The second test case is depicted below.