#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;


int score[4][4];

int winpoint[4];
int goal_diff[4];
int goal_num[4];

bool AwinB(int a, int b) {
  if (winpoint[a] != winpoint[b]) return winpoint[a] > winpoint[b];
  if (goal_diff[a] != goal_diff[b]) return goal_diff[a] > goal_diff[b];
  return goal_num[a] > goal_num[b];
}

bool AtieB(int a, int b) {
  if (!AwinB(a,b) && !AwinB(b,a)) return 1;
  return 0;
}

int num;
int rank[4];
double hoge[4];

bool printflag;

void solve(int l, int r) {
  if (r-l<=1) {
    hoge[l] = (rank[l]==num);
    return;
  }
  
  REP(i,4)winpoint[i]=goal_diff[i]=goal_num[i]=0;

  for (int i=l; i<r; ++i) {
    for (int j=l; j<r; ++j) {
      if (i==j) continue;
      int a = rank[i], b = rank[j];
      if (score[a][b] > score[b][a]) winpoint[a] += 3;
      else if(score[a][b] == score[b][a]) winpoint[a]++;
      goal_diff[a] += score[a][b] - score[b][a];
      goal_num[a] += score[a][b];
    }
  }

  if (printflag) {
    for (int i=l; i<r; ++i) cout << winpoint[i] << " "; cout << endl;
    for (int i=l; i<r; ++i) cout << goal_diff[i] << " "; cout << endl;
    for (int i=l; i<r; ++i) cout << goal_num[i] << " "; cout << endl;
  }
  
  sort(rank+l, rank+r, AwinB);

  int start = l;
  vector<pii> tmp;
  for (int i=l+1; i<r; ++i) {
    if (!AtieB(rank[start], rank[i])) {
      tmp.push_back(pii(start,i));
      start = i;
    }
  }
  FOR(it, tmp) solve(it->first, it->second);
  if (start == l) {
    bool f = 0;
    for (int i=l; i<r; ++i) if (rank[i] == num) f = 1;
    for (int i=l; i<r; ++i) hoge[i] = (f?1.0/(r-l):0);
    return;
  }
  solve(start,r);
}

double prob(int p) {
  double res = 1;
  for (int i=1; i<=8; ++i) res *= i;
  for (int i=1; i<=p; ++i) res /= i;
  for (int i=1; i<=(8-p); ++i) res /= i;
  REP(i,p) res /= 4;
  REP(i,8-p) res *= 3.0/4;
  return res;
}

int main() {
  int T;
  cin>>T;
  while(T--) {
    memset(score,-1,sizeof(score));
    vector<pii> v;
    REP(i,5) {
      string s;
      cin >> s;
      if (s[0] == '*') num = i-1;
      if (i>=1 && i<=3) {
        for (int j=i-1; j<3; ++j) {
          if (s[11+j*5] != '_') {
            int a = s[11+j*5]-'0';
            int b = s[13+j*5]-'0';
            score[i-1][j+1] = a;
            score[j+1][i-1] = b;
          } else {
            v.push_back(pii(i-1,j+1));
          }
        }
      }
    }
    assert(v.size() == 2);
    double ans = 0;
    REP(a,9) {
      REP(b,9) {
        REP(c,9) {
          REP(d,9) {
            double p = prob(a)*prob(b)*prob(c)*prob(d);
            REP(i,2) {
              int x = v[i].first;
              int y = v[i].second;
              if (i == 0) {
                score[x][y] = a;
                score[y][x] = b;
              } else {
                score[x][y] = c;
                score[y][x] = d;
              }
            }
            REP(i,4) rank[i] = i;
            REP(i,4) hoge[i] = -1;
            
            // if (a==2&&b==1&&c==0&&d==0) printflag = 1;
            // else printflag = 0;
            printflag = 0;
            
            solve(0,4);

            REP(i,4) {
              if (hoge[i] == -1) printflag = 1;
            }
            
            if (printflag) {
              REP(i,4) {
                REP(j,4) {
                  cout << score[i][j] << " ";
                }
                cout << endl;
              }
              REP(i,4) cout << rank[i] << " "; cout << endl;
              REP(i,4) cout << hoge[i] << " "; cout << endl;
            }

            REP(i,2) ans += p*hoge[i];
            // REP(i,2) {
            //   if (rank[i] == num) {
            //     if (hoge[i] == -1) ans += p;
            //     else {
            //       if (i==0) ans += p*2/hoge[i];
            //       else ans += p/hoge[i];
            //     }
            //   }
            // }
            // cout << a << " " << b << " " << c << " " << d << endl;
          }
        }
      }
    }
    printf("%.10f\n", ans);
  }
}

Measured memory_bytes: 1264