#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int ast,game[4][4];

int score(int t){
  if(game[t][t]<0)return -1000;
  int res=0;
  for(int i=0;i<4;i++) {
    if(game[i][i]<0)continue;
    int a=game[t][i],b=game[i][t];
    if(a>b) res+=3;
    if(a==b)res++;
  }    
return res;
}

int goal(int t){
  int res=0;
  for(int i=0;i<4;i++)if(game[i][i]>=0)res+=game[t][i];
  return res;
}

int ngoal(int t){
  int res=0;
  for(int i=0;i<4;i++)if(game[i][i]>=0)res+=game[i][t];
  return res;
}


bool eq(PP a,PP b){return a.f==b.f&&a.s.f==b.s.f;}

int nCr(int n,int r){
  int a=1,b=1;
  for(int i=0;i<r;i++)a*=(n-i),b*=(i+1);
  return a/b;
}

double calc(double p){return nCr(8,p)*pow(1.0/4,p)*pow(3.0/4,8-p);}

double check(int n){
  if(game[ast][ast]<0)return 0;
  PP p[4];
  for(int i=0;i<4;i++)
    p[i]=PP(P(score(i),goal(i)-ngoal(i)),P(goal(i),i));
  sort(p,p+4,greater<PP>());
  vector<int>er;

  if(eq(p[0],p[1])){
    double cnt=0;
    for(int i=0;i<4;i++){
      if(!eq(p[0],p[i])&&game[p[i].s.s][p[i].s.s]>=0)er.push_back(p[i].s.s);
      cnt+=game[i][i]>=0;
    }
    if(!er.size())return n/cnt;
  }
  else if(n==2&&eq(p[1],p[2])){
    if(p[0].s.s==ast)return 1;
    for(int i=0;i<4;i++)
      if(!eq(p[1],p[i])&&game[p[i].s.s][p[i].s.s]>=0)er.push_back(p[i].s.s);
  }
  else return p[0].s.s==ast||(n==2&&p[1].s.s==ast);

  for(int i=0;i<er.size();i++)game[er[i]][er[i]]=-1;
  double res=check(n-!eq(p[0],p[1]));
  for(int i=0;i<er.size();i++)game[er[i]][er[i]]=0;
  return res;
}

double solve(){
  double res=0;
  vector<int> x,y;
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
      if(game[i][j]==-1)y.push_back(i),x.push_back(j);
  
  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++){
	  int a[]={i,j,k,l};
	  double p=1.0;
	  for(int m=0;m<4;m++)game[y[m]][x[m]]=a[m],p*=calc(a[m]);
	  res+=check(2)*p;
	}
  return res;
}

int main(){
  int T;
  cin>>T;
  while(T--){
    memset(game,-1,sizeof(game));
    for(int i=0;i<4;i++) game[i][i]=0;
    string mp[5];
    for(int i=0;i<5;i++)cin>>mp[i];
    for(int i=0;i<4;i++)if(mp[0][5+5*i]=='*')ast=i;
    
    for(int i=0;i<4;i++)
      for(int j=i+1;j<4;j++) {
	int a=mp[i+1][5+5*j+1]-'0',b=mp[i+1][5+5*j+3]-'0';
	if(a=='_'-'0')continue;
	game[i][j]=a;
	game[j][i]=b;
      }
    printf("%.8f\n",solve());
  }
  return 0;
}