Under construction

Still being built. Things may change

Tournament turn-around

Interview

Time limit5sMemory limit512 MB

Summary
Given head-to-head win counts for eight teams, find the bracket order that maximizes team 1's chance of winning the tournament.
Level

Easy3 of 10

Topics
Brute force, Probability
Solved
No attempts yet

Problem

In the region of Concordia, the teams of a famous alliance of technical universities hold a wallyball tournament every year. Your university, Beaver Valley Institute of Mines and Telecommunication Tech, is a proud participating institution. The model of the tournament is quite simple. There are eight teams, and they are arranged in four pairs to play a quarter-final. The winners of the quarter-final are arranged in two pairs to play two semi-finals. Finally, the winners of the semi-finals meet in the final.

This year is a bit special because the alliance between the universities is about to break down. Your alma mater will lose part of its name, and this is your university's last chance to win the trophy that no one will ever be able to claim back. Your university has always practiced fair play and would never cheat. But …\dots what if good fortune could help your team a little by drawing a favorable order for the teams?

The Bureau des Sports has collected extensive statistics. Over the alliance's short history, you know how many matches each team has won over the others. We assume this gives the probability of the outcome of each individual match. If team pp has won nn times over team qq, and team qq has won mm times over team pp, then in a match between pp and qq, team pp wins with probability nn+m\frac{n}{n+m} and team qq wins with probability mn+m\frac{m}{n+m}. There are no ties. If historically pp has never won against qq, then pp has no chance of winning at the tournament. You have seen every pair of teams play at least once, so the probabilities are always well-defined.

According to this probabilistic model, what order of teams maximizes the probability that your team wins the entire tournament?

Input

The input file consists of multiple test cases. The first line contains a single integer cc, the number of test cases. Each test case consists of eight lines of eight integers separated by single spaces. For 1≤i,j≤81 \leq i, j \leq 8, the jjth integer in the iith line is how many matches team i−1i-1 won against team j−1j-1. Each integer is between zero and five. The integers on the diagonal are always zero. Every pair of teams has played at least once, so for i≠ji \neq j, either the iith integer of the jjth line or the jjth integer of the iith line is nonzero. Your university is always the first university in the input ordering.

Output

For each test case, print one line with a float followed by eight integers separated by a single space. The float is the maximum probability that your university wins the tournament, rounded to exactly 5 decimal places. The eight integers give the order of teams that achieves this probability, assuming the matches proceed according to the diagram above and each match is decided by the probabilistic model. If multiple arrangements give the same probability, print the lexicographically smallest one.

Examples1

  1. Example 1

    Input
    2
    0 1 1 1 1 1 1 1
    0 0 1 1 1 1 1 1
    0 0 0 1 1 1 1 1
    0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1
    0 0 0 0 0 0 1 1
    0 0 0 0 0 0 0 1
    0 0 0 0 0 0 0 0
    0 4 1 2 3 0 1 1
    1 0 1 5 4 3 2 5
    4 4 0 4 2 1 5 5
    3 5 1 0 3 5 4 4
    2 1 3 2 0 5 4 3
    5 2 4 0 0 0 1 4
    4 3 5 1 1 4 0 2
    4 5 0 1 2 1 3 0
    
    Expected output
    1.00000 0 1 2 3 4 5 6 7
    0.14054 0 1 3 7 2 5 4 6