Single Elimination

Given the fixed win/loss outcome for every pair among 16 players, decide which players can be made champion by choosing all four rounds of pairings.

Medium7BacktrackingDivide and conquerBit manipulationDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

Single elimination is the bracket format used by the major tennis tournaments, the American college basketball tournament, the college football playoff, and many Olympic events. It fits most neatly when the number of players nn is a power of 2. In each round the remaining players are paired up and play their matches. Every loser is out, and only the winners go on to the next round. After log2n\log_2 n rounds one player is left, and that player wins.

If one player beats every other player, that player always wins. The situation gets interesting once every player has one or more opponents they have trouble with. A player who is unlucky and meets such an opponent early is eliminated, and another player who would have lost to them later benefits from it. Deciding who plays whom in each round is therefore a useful tool for making your favorite player win.

16 players enter. For every pair of players it is fixed in advance who wins when those two play, and the result always comes out that way. You set the first round pairings, and for the second round you can pair up the first round winners however you like. The third and fourth rounds work the same way. A player has a chance to win if some bracket designed in that player's favor leaves them as the last one standing. Find every player who has a chance to win.

Input

The first line has the number of data sets KK. The KK data sets follow, each in this form.

A data set has 16 lines, and each line has 16 numbers ai,j{0,1}a_{i,j} \in \{0, 1\}. If ai,j=1a_{i,j} = 1, player ii beats player jj when the two play. If ai,j=0a_{i,j} = 0, player jj beats player ii. For two different players ii and jj, exactly one of ai,ja_{i,j} and aj,ia_{j,i} is 1. Player ii never plays against himself or herself, so the value of ai,ia_{i,i} means nothing. It is there to make the input easier to parse.

Output

For each data set, first print Data Set x: on a line of its own, where xx is the number of the data set counting from 1. On the next line print the numbers of all players who can win the tournament when the bracket is designed in their favor, in increasing order, separated by single spaces, all on one line. Print one blank line after each data set.