#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
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;}

#define INF 1120000000


double prob[10];

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

int f[4][4], g[4][4];
// f ??????, g ??±???
int star;

double match(vector<int> players, int rank){
  using P = pair<pair<int,int>,pair<int,int>>;
  #define id se.se

  vector<P> vec;

  for(auto i : players){
    P p = {{0,0},{0,i}};
    for(auto j : players) if(i!=j){
      if(f[i][j] > g[i][j]) p.fi.fi += 3;
      if(f[i][j] == g[i][j]) p.fi.fi += 1;
      p.fi.se += f[i][j] - g[i][j];
      p.se.fi += f[i][j];
    }
    vec.pb(p);
  }

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

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

  int sz = players.size();

  int sr = -1;
  rep(i,vec.size()) if(vec[i].id == star) sr = i;
  while(sr>0 && eq(sr,sr-1)) sr--;

  if(sz == 4){
    if(sr==0){
      if(eq(0,3)) return 0.5;
      else if(eq(0,2)) return match({vec[0].id, vec[1].id, vec[2].id}, 2);
      else return 1;
    }
    if(sr==1){
      if(eq(1,3)) return match({vec[3].id, vec[1].id, vec[2].id}, 1);
      else if(eq(1,2)) return  match({vec[1].id, vec[2].id}, 1);
      else return 1;
    }
    return 0;
  }

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

  if(sz == 3 && rank == 2){
    if(sr==0){
      if(eq(0,2)) return 2.0/3.0;
      return 1;
    }
    if(sr==1){
      if(eq(1,2)) return 0.5;
      return 1;
    }
    return 0;
  }

  if(sz==2 && rank == 1){
    if(sr==0){
      if(eq(0,1)) return 0.5;
      else return 1;
    }
    return 0;
  }

  assert(false);
}

double solve(){
  string s[5];
  rep(i,5) cin>>s[i];

  int x = 0;
  int ui[2], uj[2];
  rep(j,4)rep(i,j){
    if(s[i+1][j*5+6]=='_'){
      ui[x] = i; uj[x] = j;
      x++;
    } else {
      f[i][j] = g[j][i] = s[i+1][j*5+6] - '0';
      f[j][i] = g[i][j] = s[i+1][j*5+8] - '0';
    }
  }

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

  double ans = 0;
  rep(i,9)rep(j,9)rep(k,9)rep(l,9){
    double p = prob[i]*prob[j]*prob[k]*prob[l];
    f[ui[0]][uj[0]] = g[uj[0]][ui[0]] = i;
    f[uj[0]][ui[0]] = g[ui[0]][uj[0]] = j;
    f[ui[1]][uj[1]] = g[uj[1]][ui[1]] = k;
    f[uj[1]][ui[1]] = g[ui[1]][uj[1]] = l;
    ans += p * match({0,1,2,3}, 2);
  }

  return ans;
}

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

  int n;
  cin>>n;
  rep(i,n){
    printf("%.9f\n", solve());
  }

  return 0;
}

Measured memory_bytes: 3304