logo AlgoBeat OnlineJudge
登录 注册

#214569. [2019 KAIST RUN Fall] Gosu 2

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Ho is an expert in martial arts called . She runs a Taebo school, and there are students in her school. To increase the inner competition inside the Taebo school, she is going to make a which assigns all students to a certain rank. To find a suitable rank, Ho made all pairs of students do a Taebo matchup with each other. In a Taebo matchup, exactly one person wins the match, and another person loses the match. The outcome of Taebo matchups may not be very simple: For example, there might be a case that student A beats B, B beats C, and C beats A. Such situation would make the ranking assignment pretty complicated as there is no definite winner from those three students.

To overcome the issue, Ho will find a and assign other students with respect to such a chain. A of length , is a sequence of different students such that beats if and only if . In other words, can beat all other students in the chain, can beat all other students in the chain except , can beat all other students in the chain except , and so on, and can beat no other student in the chain. Ho's website will assign other students based on such a chain, which will make the assignment easier.

Ho is not only an expert in Taebo, but she is a math genius too. Ho knows, that for any Taebo matchup, she can find the standard ranking chain of length , where is a base 2 logarithm. In other words, for any such that , Ho can find a standard ranking chain of such a length.

While Ho is very good at computer programming too, she is a little bit lazy, therefore she delegates her work to you. You should find a standard ranking chain of length exactly .

输入格式

In the first line, the number of test cases is given. For each test case, the following instances are given:

In the first line, the number of students is given.

In the -th line of the next lines, a string consisting of , , and , is given. Let's denote the -th character of as . is given as follows:

  • , if .
  • , if student won student .
  • , if student won student .
  • The sum of for all test cases does not exceed .
  • ()
  • If , then or . ()
  • If , then . ()
  • If , then . ()

输出格式

For each test case, print exactly integers in a single line, denoting the students in a standard ranking chain in the order of their skills. It can be proved that such a chain exists for every possible input.

样例

样例输入 1

5
1
-
2
-W
L-
3
-LW
W-L
LW-
4
-WLW
L-WL
WL-W
LWL-
5
-WLLW
L-LLW
WW-LL
WWW-W
LLWL-

样例输出 1

1
1 2
3 2
3 1 4
4 3 1