#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define double long double
const int mod=1000000007,MAX=203,INF=1<<20;

struct data{
    int point;
    int diff;
    int goal;
    int id;
    
    bool operator<(const data &another) const
    {
        if(point==another.point){
            if(diff==another.diff){
                if(goal==another.goal){
                    return id<another.id;
                }
                return goal<another.goal;
            }
            return diff<another.diff;
        }
        return point<another.point;
    };
    
    bool operator == (const data &another) const
    {
        return point==another.point&&diff==another.diff&&goal==another.goal;
    };
};

vector<int> dh={1,1,1,2,2,3},dw={11,16,21,16,21,21};

void f(data &a,data &b,int scorea,int scoreb){
    if(scorea==scoreb){
        a.point++;
        b.point++;
        a.goal+=scorea;
        b.goal+=scoreb;
    }else if(scorea>scoreb){
        a.point+=3;
        a.diff+=scorea-scoreb;
        b.diff+=scoreb-scorea;
        a.goal+=scorea;
        b.goal+=scoreb;
    }else{
        b.point+=3;
        a.diff+=scorea-scoreb;
        b.diff+=scoreb-scorea;
        a.goal+=scorea;
        b.goal+=scoreb;
    }
    
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    vector<double> p(9);
    for(double i=0.0;i<=8.0;i++){
        p[i]=1.0;
        for(double j=1.0;j<=8.0;j++) p[i]*=j;
        for(double j=1.0;j<=i;j++) p[i]/=j;
        for(double j=1.0;j<=8.0-i;j++) p[i]/=j;
        
        for(double j=1.0;j<=8.0-i;j++) p[i]*=3.0;
        for(double j=1.0;j<=8.0;j++) p[i]/=4.0;
    }
    
    while(Q--){
        vector<string> S(5);
        for(int i=0;i<5;i++) cin>>S[i];
        double ans=0.0;
        int my;
        vector<data> T(4);
        
        for(int i=1;i<5;i++) if(S[i][0]=='*') my=i-1;
        
        vector<pair<int,int>> ch;
        
        for(int k=0;k<6;k++){
            if(S[dh[k]][dw[k]]=='_'){
                ch.push_back({dh[k],dw[k]});
                ch.push_back({dh[k],dw[k]+2});
            }
        }
        
        for(int q1=0;q1<9;q1++){
            for(int q2=0;q2<9;q2++){
                for(int q3=0;q3<9;q3++){
                    for(int q4=0;q4<9;q4++){
                        double pp=p[q1]*p[q2]*p[q3]*p[q4];
                        vector<int> sco(4);
                        sco[0]=q1;
                        sco[1]=q2;
                        sco[2]=q3;
                        sco[3]=q4;
                        
                        for(int k=0;k<4;k++) S[ch[k].first][ch[k].second]=char('0'+sco[k]);
                        
                        vector<int> use(4,0);
                        
                        while(1){
                            vector<data> T(4);
                            int fi=0;
                            for(int i=0;i<4;i++){
                                T[i].id=i;
                                if(use[i]==1) T[i].point+=1000;
                                if(use[i]==2) T[i].point-=1000;
                                if(use[i]==0) fi++;
                            }
                            
                            for(int k=0;k<6;k++){
                                int a=S[dh[k]][dw[k]]-'0',b=S[dh[k]][dw[k]+2]-'0';
                                
                                if(use[dh[k]-1]||use[(dw[k]-6)/5]) continue;
                                
                                f(T[dh[k]-1],T[(dw[k]-6)/5],a,b);
                                
                                //cout<<a<<" "<<b<<endl;
                            }
                            
                            int cnta=0,cntb=0;
                            for(int i=0;i<4;i++){
                                //if(i==my) continue;
                                if(!(T[i]==T[my])){
                                    if(T[i]<T[my]) cntb++;
                                    if(T[my]<T[i]) cnta++;
                                }
                            }
                            
                            int posa,posb;
                            posa=cnta;
                            posb=3-cntb;
                            
                            sort(all(T));
                            reverse(all(T));
                            
                            if(posb<=1){
                                ans+=pp;
                                break;
                            }else if(posa>=2){
                                break;
                            }else{
                                if(fi==posb-posa+1){
                                    double cnt=0;
                                    for(int i=posa;i<=posb;i++) if(i<=1) cnt++;
                                    ans+=pp*cnt/(double)(fi);
                                    break;
                                }else{
                                    for(int i=0;i<posa;i++) use[T[i].id]=1;
                                    for(int i=posb+1;i<4;i++) use[T[i].id]=2;
                                    for(int i=posa;i<=posb;i++){
                                        //if(use[T[i].id]) cout<<"!"<<endl;
                                        use[T[i].id]=0;
                                    }
                                }
                            }
                        }
                        
                        for(int k=0;k<4;k++) S[ch[k].first][ch[k].second]='_';
                    }
                }
            }
        }
        cout<<fixed<<setprecision(7)<<ans<<endl;
    }
}




Measured memory_bytes: 3304