Escape Room
시간 제한1초메모리 제한256 MB
모든 열쇠 부분집합마다 전체 연결 여부가 주어질 때, 그 패턴을 정확히 만족하는 사이트 300개 이하의 미로를 만들거나 불가능함을 판정한다.
문제
Busy Beaver is designing an escape room! His current design is a maze with different sites, where each of the pairs of sites is directly connected by a bidirectional tunnel.
To make the maze more interesting, each tunnel is locked with one of () keys, numbered . One can only traverse a tunnel between sites and if they have its corresponding key .
Additionally, Busy Beaver wants to design the maze such that only certain sets of keys let you traverse the entire maze. In particular, there are for each subset such that
- If , it is possible to move between any two sites in the maze using only the keys in .
- If , there exists some pair of sites that cannot be accessed from each other using only the keys in .
Decide whether or not the task is possible. Additionally, if the task is possible, provide any valid construction with at most sites.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains the integer () --- the number of keys.
The second line of each test case contains a string (, ) such that for each , if then . Note that the string is zero-indexed, that is, .
It is guaranteed that the sum of across all test cases is no more than .
출력
For each test case, if it is possible to satisfy the given constraints, the first line of output should contain an integer () --- the number of sites. The -th of the next lines of output should then contain integers ( for ), where for , the tunnel between sites and uses key .
If there are multiple solutions, print any of them. Otherwise, if there is no solution, print a single integer instead.
Due to judging constraints, the sum of over your outputs should not exceed . It can be shown that this is enough to solve the problem.
힌트
In the first test case, it can be shown that it is impossible to construct the desired maze.
In the second test case, a possible construction is a maze with sites connected by a tunnel using key .
- With keys corresponding to , it is impossible to traverse the entire maze.
- With keys corresponding to , it is possible to traverse the entire maze.
- With keys corresponding to , it is impossible to traverse the entire maze.
- With keys corresponding to , it is possible to traverse the entire maze.
In the third test case, it can be shown that it is impossible to construct the desired maze.
In the fourth test case, a possible construction is the following maze with sites:

In the fifth test case, a possible construction is a maze with only site. With any set of keys, it is possible to traverse the entire maze.