Problem: Following FIFA World Cup, a larger competition called ``GIGA Universe Cup'' is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as ``group league,'' and the second called ``final tournament.'' In the first round, participating teams are divided into groups of four teams each. Each team in a group plays a match against each of the other teams in the same group. For example, let's say we have a group of the following four teams, ``Engband, Swedon, Argontina, and Nigerua.'' They play the following six matches: Engband - Swedon, Engband - Argontina, Engband - Nigerua, Swedon - Argontina, Swedon - Nigerua, and Argontina - Nigerua.

The result of a single match is shown by the number of goals scored by each team, like ``Engband 1 - 0 Argontina,'' which says Engband scored one goal whereas Argontina zero. Based on the result of a match, points are given to the two teams as follows and used to rank teams. If a team wins a match (i.e., scores more goals than the other), three points are given to it and zero to the other. If a match draws (i.e., the two teams score the same number of goals), one point is given to each.

The goal difference of a team in given matches is the total number of goals it scored minus the total number of goals its opponents scored in these matches. For example, if we have three matches ``Swedon 1 - 2 Engband,'' ``Swedon 3 - 4 Nigerua,'' and ``Swedon 5 - 6 Argontina,'' then the goal difference of Swedon in these three matches is (1 + 3 + 5) - (2 + 4+ 6) = -3.

Given the results of all the six matches in a group, teams are ranked by the following criteria, listed in the order of priority (that is, we first apply (a) to determine the ranking, with ties broken by (b), with ties broken by (c), and so on).

(a) greater number of points in all the group matches;

(b) greater goal difference in all the group matches;

(c) greater number of goals scored in all the group matches.

If two or more teams are equal on the basis of the above three criteria, their place shall be determined by the following criteria, applied in this order:

(d) greater number of points obtained in the group matches between the teams concerned;

(e) greater goal difference resulting from the group matches between the teams concerned;

(f) greater number of goals scored in the group matches between the teams concerned;

If two or more teams are stiIl equal, apply (d), (e), and (f) as necessary to each such group. Repeat this until those three rules to equal teams do not make any further resolution. Finally, teams that still remain equal are ordered by:

(g) drawing lots by the Organizing Committee for the GIGA Universe Cup.

The two teams coming first and second in each group qualify for the second round.

Your job is to write a program which, given the results of matches played so far in a group and one team specified in the group, calculates the probability that the specified team will qualify for the second round. You may assume each team has played exactly two matches and has one match to play. In total, four matches have been played and two matches are to be played.

Assume the probability that any team scores (exactly) p goals in any match is:

<image>

for p ≤ 8, and zero for p > 8 . Assume the lot in the step (g) is fair.



Input

The first line of the input is an integer, less than 1000, that indicates the number of subsequent records.

The rest of the input is the indicated number of records. A single record has the following format:

<image>

In the above, <_> is a single underscore (_) and <empty> a sequence of exactly four underscores (____). Each of <team>1, ... , <team>4 is either an asterisk character (*) followed by exactly three uppercase letters (e.g., *ENG), or an underscore followed by exactly three uppercase letters (e.g., _SWE). The former indicates that it is the team you are asked to calculate the probability of the second round qualification for. You may assume exactly one of <team>1, ... , <team>4 is marked with an asterisk. Each <m>ij(1 ≤ i < j ≤ 4) is a match result between the <team>i and <team>j. Each match result is either __-_ (i.e., two underscores, hyphen, and another underscore) or of the form _x-y where each of x and y is a single digit (≤ 8) . The former indicates that the corresponding match has not been played, whereas the latter that the result of the match was x goals by <team>i and y goals by <team>j. Since each team has played exactly two matches, exactly two match results are in the former format.

Output

The output should consist of n lines where n is the number of records in the input. The ith line should show the probability that the designated team (marked with an asterisk) will qualify for the second round in the ith record.

Numbers should be printed with exactly seven digits after the decimal point. Each number should not contain an error greater than 10-7.

Example

Input

5
_____*AAA__BBB__CCC__DDD
*AAA_______0-0__0-0___-_
_BBB_____________-___0-0
_CCC_________________0-0
_DDD____________________
______CHN__CRC__TUR_*BRA
_CHN_______0-2___-___0-4
_CRC____________1-1___-_
_TUR_________________1-2
*BRA____________________
______CMR_*KSA__GER__IRL
_CMR_______1-0___-___1-1
*KSA____________0-8___-_
_GER_________________1-1
_IRL____________________
______TUN__JPN_*BEL__RUS
_TUN________-___1-1__0-2
_JPN____________2-2__1-0
*BEL__________________-_
_RUS____________________
______MEX__CRO_*ECU__ITA
_MEX_______1-0__2-1___-_
_CRO_____________-___2-1
*ECU_________________0-2
_ITA____________________


Output

0.5000000
1.0000000
0.0000000
0.3852746
0.0353304

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(7) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

double pro[10];
pair<Int, Int> score[5][5];

void calc_pro() {
    double x[10];
    x[0] = x[1] = 1.0;
    for (int i = 1; i <= 8; i++) {
        x[i + 1] = x[i] * (double)(i + 1);
    }
    for (int i = 0; i <= 8; i++) {
        pro[i] = x[8] / (x[i] * x[8 - i]);
        for (int j = 0; j < i; j++) {
            pro[i] *= 1.0 / 4.0;
        }
        for (int j = 0; j < 8 - i; j++) {
            pro[i] *= 3.0 / 4.0;
        }
    }
}

void s(vector<vector<Int>> &v, Int x) {
    for (Int i = 0; i < (Int)v.size(); i++) {
        for (Int j = 0; j < (Int)v.size() - 1; j++) {
            if (v[j][x] < v[j + 1][x]) {
                swap(v[j], v[j + 1]);
            }
        }
    }
}

double f(vector<vector<Int>> v, Int check_team) {
    s(v, 2);
    s(v, 1);
    s(v, 0);
    vector<Int> rank[4];
    rank[0].push_back(v[0][3]);
    Int pre = 0;
    for (Int i = 1; i < 4; i++) {
        if (v[i - 1][0] == v[i][0] and v[i - 1][1] == v[i][1] and v[i - 1][2] == v[i][2]) {
            rank[pre].push_back(v[i][3]);
        } else {
            pre++;
            rank[pre].push_back(v[i][3]);
        }
    }
    if (rank[0].size() == 4) {
        return 1.0 / 2.0;
    }
    if (rank[0].size() == 3) {
        if (rank[1][0] == check_team) {
            return 0.0;
        } else {
            Int ex = rank[1][0];
            Int mp[4];
            for (Int i = 0; i < 4; i++) {
                mp[v[i][3]] = i;
            }
            for (Int i = 0; i < 4; i++) {
                if (i == ex) continue;
                Int a = score[ex][i].first;
                Int b = score[ex][i].second;
                if (a < b) {
                    v[mp[i]][0] -= 3;
                }
                if (a == b) {
                    v[mp[i]][0] -= 1;
                }
                v[mp[i]][1] -= b - a;
                v[mp[i]][2] -= b;
            }
            vector<vector<Int>> v2;
            for (Int i = 0; i < 4; i++) {
                if (v[i][3] == ex) continue;
                v2.push_back(v[i]);
            }
            s(v2, 2);
            s(v2, 1);
            s(v2, 0);
            vector<Int> rank2[3];
            rank2[0].push_back(v2[0][3]);
            Int pre = 0;
            for (Int i = 1; i < 3; i++) {
                if (v2[i - 1][0] == v2[i][0] and v2[i - 1][1] == v2[i][1] and v2[i - 1][2] == v2[i][2]) {
                    rank2[pre].push_back(v2[i][3]);
                } else {
                    pre++;
                    rank2[pre].push_back(v2[i][3]);
                }
            }
            if (rank2[0].size() == 3) {
                return 2.0 / 3.0;
            }
            if (rank2[0].size() == 2) {
                if (rank2[1][0] == check_team) {
                    return 0.0;
                } else {
                    return 1.0;
                }
            }
            if (rank2[0].size() == 1) {
                if (rank2[0][0] == check_team) {
                    return 1.0;
                } else {
                    if (rank2[1].size() == 1) {
                        if (rank2[1][0] == check_team) {
                            return 1.0;
                        } else {
                            return 0.0;
                        }
                    } else {
                        assert(rank2[1].size() == 2);
                        Int a = score[rank2[1][0]][rank2[1][1]].first;
                        Int b = score[rank2[1][0]][rank2[1][1]].second;
                        if (a == b) {
                            return 1.0 / 2.0;
                        } else {
                            if ((a > b and rank2[1][0] == check_team) or (a < b and rank2[1][1] == check_team)) {
                                return 1.0;
                            } else {
                                return 0.0;
                            }
                        }
                    }
                }
            }
        }
    }
    if (rank[0].size() == 2) {
        if (rank[0][0] == check_team or rank[0][1] == check_team) {
            return 1.0;
        } else {
            return 0.0;
        }
    }
    if (rank[0].size() == 1) {
        if (rank[0][0] == check_team) {
            return 1.0;
        } else {
            if (rank[1].size() == 3) {
                Int ex = rank[0][0];
                Int mp[4];
                for (Int i = 0; i < 4; i++) {
                    mp[v[i][3]] = i;
                }
                for (Int i = 0; i < 4; i++) {
                    if (i == ex) continue;
                    Int a = score[ex][i].first;
                    Int b = score[ex][i].second;
                    if (a < b) {
                        v[mp[i]][0] -= 3;
                    }
                    if (a == b) {
                        v[mp[i]][0] -= 1;
                    }
                    v[mp[i]][1] -= b - a;
                    v[mp[i]][2] -= b;
                }
                vector<vector<Int>> v2;
                for (Int i = 0; i < 4; i++) {
                    if (v[i][3] == ex) continue;
                    v2.push_back(v[i]);
                }
                s(v2, 2);
                s(v2, 1);
                s(v2, 0);
                vector<Int> rank2[3];
                rank2[0].push_back(v2[0][3]);
                Int pre = 0;
                for (Int i = 1; i < 3; i++) {
                    if (v2[i - 1][0] == v2[i][0] and v2[i - 1][1] == v2[i][1] and v2[i - 1][2] == v2[i][2]) {
                        rank2[pre].push_back(v2[i][3]);
                    } else {
                        pre++;
                        rank2[pre].push_back(v2[i][3]);
                    }
                }
                if (rank2[0].size() == 3) {
                    return 1.0 / 3.0;
                }
                if (rank2[0].size() == 2) {
                    if (rank2[1][0] == check_team) {
                        return 0.0;
                    } else {
                        Int a = score[rank2[0][0]][rank2[0][1]].first;
                        Int b = score[rank2[0][0]][rank2[0][1]].second;
                        if (a == b) {
                            return 1.0 / 2.0;
                        } else {
                            if ((a > b and rank2[0][0] == check_team) or (a < b and rank2[0][1] == check_team)) { 
                                return 1.0;
                            } else {
                                return 0.0;
                            }
                        }
                    }
                }
                if (rank2[0].size() == 1) {
                    if (rank2[0][0] == check_team) {
                        return 1.0;
                    } else {
                        return 0.0;
                    }
                }
            }
            if (rank[1].size() == 2) {
                if (rank[2][0] == check_team) {
                    return 0.0;
                } else {
                    Int a = score[rank[1][0]][rank[1][1]].first;
                    Int b = score[rank[1][0]][rank[1][1]].second;
                    if (a == b) {
                        return 1.0 / 2.0;
                    } else {
                        if ((a > b and rank[1][0] == check_team) or (a < b and rank[1][1] == check_team)) { 
                            return 1.0;
                        } else {
                            return 0.0;
                        }
                    }
                }
            }
            if (rank[1].size() == 1) {
                if (rank[1][0] == check_team) {
                    return 1.0;
                } else {
                    return 0.0;
                }
            }
        }
    }
}

int main() {
    Int t;
    cin >> t;
    calc_pro();
    vector<double> r;
    while (t--) {
        vector<vector<Int>> v(4, vector<Int>(4, 0));
        for (Int i = 0; i < 4; i++) v[i][3] = i;
        Int check_team = -1;
        pair<Int, Int> b1 = {-1, -1}, b2 = {-1, -1};
        for (Int i = 0; i <= 4; i++) {
            string s;
            cin >> s;
            if (i == 0) continue;
            if (s[0] == '*') {
                check_team = i - 1;
            }
            for (Int j = (i + 1) * 5; j < (Int)s.size(); j+=5) {
                Int team_A = i - 1;
                Int team_B = j / 5 - 1;
                Int point_A = -1, point_B = -1;
                for (Int k = 0; k < 4; k++) {
                    if (k == 1 and s[j + k] != '_') {
                        point_A = s[j + k] - '0';
                    }
                    if (k == 3 and s[j + k] != '_') {
                        point_B = s[j + k] - '0';
                    }
                }
                score[team_A][team_B] = {point_A, point_B};
                score[team_B][team_A] = {point_B, point_A};
                if (point_A < 0) {
                    if (b1.first < 0) {
                        b1 = {team_A, team_B};
                    } else {
                        b2 = {team_A, team_B};
                    }
                } else {
                    if (point_A > point_B) {
                        v[team_A][0] += 3;
                    } else if (point_A < point_B) {
                        v[team_B][0] += 3;
                    } else {
                        v[team_A][0] += 1;
                        v[team_B][0] += 1;
                    }
                    v[team_A][1] += point_A - point_B;
                    v[team_B][1] += point_B - point_A;
                    v[team_A][2] += point_A;
                    v[team_B][2] += point_B;
                }
            }
        }
        double res = 0;
        for (Int i = 0; i <= 8; i++) {
            for (Int j = 0; j <= 8; j++) {
                if (i > j) {
                    v[b1.first][0] += 3;
                } else if (i < j) {
                    v[b1.second][0] += 3;
                } else {
                    v[b1.first][0] += 1;
                    v[b1.second][0] += 1;
                }
                v[b1.first][1] += i - j;
                v[b1.second][1] += j - i;
                v[b1.first][2] += i;
                v[b1.second][2] += j;
                score[b1.first][b1.second] = {i, j};
                score[b1.second][b1.first] = {j, i};
                for (Int k = 0; k <= 8; k++) {
                    for (Int l = 0; l <= 8; l++) {
                        if (k > l) {
                            v[b2.first][0] += 3;
                        } else if (k < l) {
                            v[b2.second][0] += 3;
                        } else {
                            v[b2.first][0] += 1;
                            v[b2.second][0] += 1;
                        }
                        v[b2.first][1] += k - l;
                        v[b2.second][1] += l - k;
                        v[b2.first][2] += k;
                        v[b2.second][2] += l;
                        score[b2.first][b2.second] = {k, l};
                        score[b2.second][b2.first] = {l, k};
                        
                        // double p = f(v, check_team);

                        // if (i > j and k < l and p != 0 and p != 1) {
                        //     print("-------");
                        //     for (Int i = 0; i < (Int)v.size(); i++) {
                        //         print(v[i]);
                        //     }
                        //     print(f(v, check_team));
                        // }

                        res += pro[i] * pro[j] * pro[k] * pro[l] * f(v, check_team);

                        if (k > l) {
                            v[b2.first][0] -= 3;
                        } else if (k < l) {
                            v[b2.second][0] -= 3;
                        } else {
                            v[b2.first][0] -= 1;
                            v[b2.second][0] -= 1;
                        }
                        v[b2.first][1] -= k - l;
                        v[b2.second][1] -= l - k;
                        v[b2.first][2] -= k;
                        v[b2.second][2] -= l;
                    }
                }
                if (i > j) {
                    v[b1.first][0] -= 3;
                } else if (i < j) {
                    v[b1.second][0] -= 3;
                } else {
                    v[b1.first][0] -= 1;
                    v[b1.second][0] -= 1;
                }
                v[b1.first][1] -= i - j;
                v[b1.second][1] -= j - i;
                v[b1.first][2] -= i;
                v[b1.second][2] -= j;
            }
        }
        r.push_back(res);
        //print(ma);
    }
    for (Int i = 0; i < (Int)r.size(); i++) {
        print(r[i]);
    }
    return 0;
}