#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

double fact(int k){
    if(k<=1) return 1;
    return fact(k-1)*k;
}

double prob[9];

int give[4][4]={},gett[4][4]={};
int star;


double match(vector<int> players, int jun = 1){
    using P = pair<pair<int,int>,pair<int,int>>;
    vector<P> vec;

    for(auto p : players){
        P tp;
        tp.se.se = p;
        for(auto q : players)if(p!=q){
            tp.se.fi += gett[p][q];
            int x = gett[p][q] - give[p][q];
            tp.fi.se += x;
            if(x == 0) tp.fi.fi += 1;
            else if(x > 0) tp.fi.fi += 3;
        }
        vec.pb(tp);
    }

    sort(all(vec));
    reverse(all(vec));

    int rank = -1;
    rep(i,vec.size()){
        if(vec[i].se.se == star) rank = i;
    }
    assert(rank!=-1);

    auto eq = [&](int i, int j){
        auto p = vec[i]; p.se.se = 0;
        auto q = vec[j]; q.se.se = 0;
        return p==q;
    };

    while(rank>0 && eq(rank-1,rank)) rank--;

    if(vec.size()==4){
        if(rank==0){
            if(eq(0,3)) return 0.5;
            if(eq(0,2)) return match({vec[0].se.se, vec[1].se.se, vec[2].se.se}, 1);
            return 1;
        }
        if(rank==1){
            if(eq(1,3)) return match({vec[1].se.se, vec[2].se.se, vec[3].se.se}, 0);
            if(eq(1,2))  return match({vec[1].se.se, vec[2].se.se}, 0);
            return 1;
        }
        return 0;
    }

    if(vec.size()==3 && jun == 1){
        if(rank==0){
            if(eq(0,2)) return 2.0/3.0;
            return 1;
        }
        if(rank==1){
            if(eq(1,2)) return match({vec[1].se.se, vec[2].se.se}, 0);
            return 1;
        }
        return 0;
    }

    if(vec.size()==3 && jun == 0){
        if(rank==0){
            if(eq(0,2)) return 1.0/3.0;
            if(eq(0,1)) return match({vec[0].se.se, vec[1].se.se}, 0);
            return 1;
        }
        return 0;
    }

    if(vec.size()==2 && jun == 1) assert(false);

    if(vec.size()==2 && jun == 0){
        if(rank==0){
            if(eq(0,1)) return 0.5;
            return 1;
        }
        return 0;
    }
    assert(false);
}

int main()
{
    rep(p,9){
        prob[p] = fact(8)/fact(p)/fact(8-p)*pow(0.25,p)*pow(0.75,8-p);
    }

    int dataset;
    cin>>dataset;
    while(dataset--){
        string s[5];
        rep(i,5)cin>>s[i];

        int uki[2], ukj[2];
        int tmp = 0;


        rep(i,4){
            for(int j=i+1; j<4; j++){
                if(s[i+1][j*5+6]=='_'){
                    uki[tmp] = i;
                    ukj[tmp] = j;
                    tmp++;
                } else {
                    gett[i][j] = give[j][i] = s[i+1][j*5+6] - '0';
                    give[i][j] = gett[j][i] = s[i+1][j*5+8] - '0';
                }
            }
        }

        rep(i,4) if(s[i+1][0]=='*') star = i;

        double res = 0;
        rep(x,9)rep(y,9)rep(z,9)rep(w,9){
            double p = prob[x]*prob[y]*prob[z]*prob[w];
            gett[uki[0]][ukj[0]] = give[ukj[0]][uki[0]] = x;
            gett[ukj[0]][uki[0]] = give[uki[0]][ukj[0]] = y;
            gett[uki[1]][ukj[1]] = give[ukj[1]][uki[1]] = z;
            gett[ukj[1]][uki[1]] = give[uki[1]][ukj[1]] = w;
            res += p * match({0,1,2,3});
        }

        printf("%.9f\n", res);
    }
    return 0;
}

Measured memory_bytes: 3488