Walkable Strings
시간 제한3초메모리 제한2048 MB
빨간색과 파란색 간선으로 이루어진 무방향 그래프가 주어질 때, 경로로 따라갈 수 없는 가장 짧은 R/B 문자열을 찾는다.
문제
You are given an undirected graph where each edge is colored either red or blue. We define a string consisting of characters R and B to be walkable if there exists a path in the graph where the colors of the edges in the path match the characters of in order. The path is not required to be simple, so it is allowed to visit edges and vertices multiple times.
For example, consider the below graph:

In this case, the string BRRBB is walkable, because you can use this path:

Find a non-walkable string of minimum length or determine that all strings are walkable.
입력
The first line of the input contains a single integer () --- the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers and (, ) --- the number of vertices and edges in the graph, respectively.
Each of the next lines of the input describes an edge of the graph. It contains two integers and , and a character (, , B or R) --- the endpoints of the edge and its color. It is guaranteed that there is at most one edge between each unordered pair of vertices.
It is guaranteed that the sum of across all test cases is at most , and the sum of across all test cases is at most .
출력
For each test case, print a single line containing a minimum-length non-walkable string, or if all strings are walkable.
If there are multiple answers, you may print any.
힌트
The graph in the first sample case corresponds to the picture above. It can be shown that all strings of length 2 or less are walkable on this graph.
The graph in the second sample case contains no blue edges, so the string is not walkable.
It can be shown that all strings are walkable on the graph in the fourth sample case.