#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
double fact(int n){
    if(n==0) return 1;
    return n*fact(n-1);
}

double solve(int t, int r, vector<int> tl, vector<vector<int> > &score){
    int n = tl.size();
    vector<int> gp(n, 0), gd(n, 0), gn(n, 0);
    vector<pair<pair<pair<int,int>, int>, int> > cmp(n);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int ti = tl[i], tj = tl[j];
            gd[i] += score[ti][tj] -score[tj][ti];
            gd[j] += score[tj][ti] -score[ti][tj];
            gn[i] += score[ti][tj];
            gn[j] += score[tj][ti];
            if(score[ti][tj] < score[tj][ti]){
                gp[j] += 3;
            }else if(score[ti][tj] > score[tj][ti]){
                gp[i] += 3;
            }else{
                gp[i]++;
                gp[j]++;
            }
        }
    }
    for(int i=0; i<n; i++){
        cmp[i] = make_pair(make_pair(make_pair(-gp[i], -gd[i]), -gn[i]), i);
    }
    sort(cmp.begin(), cmp.end());
    vector<int> ord(n);
    for(int i=0; i<n; i++) ord[i] = cmp[i].second;

    int samecount=1;
    int start=0;
    for(int i=1; i<n; i++){
        if(gp[ord[i]]==gp[ord[0]] && gd[ord[i]]==gd[ord[0]] && gn[ord[i]]==gn[ord[0]]){
            samecount++;
        }else{
            break;
        }
    }
    if(samecount==n){
        return (double)r/n;
    }

    if(samecount==1 && r==2){
        if(tl[ord[0]]==t){
            return 1;
        }else{
            start = 1;
            samecount = 1;
            r--;
            for(int i=2; i<n; i++){
                if(gp[ord[i]]==gp[ord[1]] && gd[ord[i]]==gd[ord[1]] && gn[ord[i]]==gn[ord[1]]){
                    samecount++;
                }else{
                    break;
                }
            }
        }
    }

    for(int i=start+samecount; i<n; i++){
        if(tl[ord[i]] == t) return 0;
    }
    if(samecount==r){
        return 1;
    }
    vector<int> ntl(samecount);
    for(int i=0; i<samecount; i++){
        ntl[i] = tl[ord[start +i]];
    }
    return solve(t, r, ntl, score);
}

int main(){
    double table[9];
    for(int i=0; i<=8; i++){
        table[i] = fact(8) /(fact(i)*fact(8-i)) *pow(0.25, i) *pow(0.75, 8-i);
    }
    cout << fixed;
    cout << setprecision(7);
    
    int ds;
    cin >> ds;
    for(int r=0; r<ds; r++){
        string s;
        cin >> s;
        int t;
        vector<vector<int> > score(4, vector<int>(4, 0));
        vector<vector<int> > emp(2);
        for(int i=0; i<4; i++){
            cin >> s;
            if(s[0]=='*') t=i;
            for(int j=i+1; j<4; j++){
                int fs = 6 +5*j;
                int ss = fs +2;
                if(s[fs]=='_'){
                    emp[0].push_back(i);
                    emp[1].push_back(j);
                }else{
                    score[i][j] = s[fs]-'0';
                    score[j][i] = s[ss]-'0';
                }
            }
        }

        double ans=0;
        vector<int> tl(4);
        for(int i=0; i<4; i++) tl[i]=i;
        for(int i=0; i<=8; i++){
            for(int j=0; j<=8; j++){
                for(int k=0; k<=8; k++){
                    for(int l=0; l<=8; l++){
                        score[emp[0][0]][emp[1][0]] = i;
                        score[emp[1][0]][emp[0][0]] = j;
                        score[emp[0][1]][emp[1][1]] = k;
                        score[emp[1][1]][emp[0][1]] = l;
                        ans += table[i]*table[j]*table[k]*table[l] *solve(t, 2, tl, score);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3212