This page is still under construction.

Parts of this page are still being built. What you see may change.

Grand Game Tournament

Time limit2sMemory limit256 MB

Summary
Given partial results of a round-robin with draws, find every player who can still finish with the maximum score.
Level

Medium6 of 10

Topics
Graph, Greedy, Implementation
Solved
No attempts yet

Problem

The "Grand Game Tournament" is the most famous game competition in the world.

Every player plays exactly one 1-vs-1 game against every other player. In each game the winner earns 1 point and the loser earns 0 points; if the game is a draw, both players earn 0.5 points. After all games are finished, the player with the highest score is the champion. If several players are tied for the highest score, they play tie-break games among themselves until a single champion remains. Therefore any player whose final score equals the maximum score has a chance to win the tournament.

The tournament is still in progress and only some of the games have been played. For each player, if the not-yet-played games can be completed in some way so that this player ends up with the maximum final score (ties for first included), then that player "can win" the tournament. Find every player who can win.

Input

The first line contains the number of test cases TT (T≤100T \le 100).

Each test case is given as follows.

  • The first line contains the number of players nn (2≤n≤302 \le n \le 30).
  • The next nn lines give the current partial results as an n×nn \times n grid. The jj-th character of the ii-th line is the result of the game between player ii and player jj.
    • 1 : player ii won
    • 0 : player ii lost
    • d : draw
    • . : the game has not been played yet
    • x : i=ji = j (a player does not play against themselves)

The partial results are consistent: if row ii column jj is 1, then row jj column ii is 0, and vice versa; a cell that is d or . equals the cell in the mirrored position.

Output

For each test case, print on one line the numbers (1-indexed) of all players who can win, in ascending order, separated by spaces.

Examples1

  1. Example 1

    Input
    3
    5
    x.11d
    .x1d1
    00x.0
    0d.x.
    d01.x
    7
    x00111.
    1x01d.d
    11x1.00
    000x000
    0d.1xd1
    0.11dxd
    .d110dx
    7
    x00011.
    1x00d.d
    11x0.0.
    111x111
    0d.0xd.
    0.10dx.
    .d.0..x
    
    Expected output
    1 2
    1 2 3 5 6 7
    4