#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;
}


Measured memory_bytes: 3176