#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(7);
  vector<int> fact(9);
  fact[0] = 1;
  for (int i = 1; i < 9; i++){
    fact[i]= fact[i - 1] * i;
  }
  vector<double> p(9);
  for (int i = 0; i < 9; i++){
    p[i] = (double) fact[8] / fact[i] / fact[8 - i] * pow(0.25, i) * pow(0.75, 8 - i);
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    vector<string> S(5);
    for (int j = 0; j < 5; j++){
      cin >> S[j];
    }
    vector<vector<int>> score(4, vector<int>(4, -1));
    for (int j = 0; j < 4; j++){
      for (int k = j + 1; k < 4; k++){
        char c1 = S[j + 1][k * 5 + 6];
        if (c1 != '_'){
          score[j][k] = c1 - '0';
        }
        char c2 = S[j + 1][k * 5 + 8];
        if (c2 != '_'){
          score[k][j] = c2 - '0';
        }
      }
    }
    vector<pair<int, int>> s;
    for (int j = 0; j < 4; j++){
      for (int k = 0; k < 4; k++){
        if (j != k){
          if (score[j][k] == -1){
            s.push_back(make_pair(j, k));
          }
        }
      }
    }
    int team;
    for (int j = 0; j < 4; j++){
      if (S[j + 1][0] == '*'){
        team = j;
      }
    }
    double ans = 0;
    vector<int> r(4);
    for (r[0] = 0; r[0] <= 8; r[0]++){
      for (r[1] = 0; r[1] <= 8; r[1]++){
        for (r[2] = 0; r[2] <= 8; r[2]++){
          for (r[3] = 0; r[3] <= 8; r[3]++){
            double tmp = 1;
            for (int j = 0; j < 4; j++){
              tmp *= p[r[j]];
            }
            vector<vector<int>> result = score;
            for (int j = 0; j < 4; j++){
              result[s[j].first][s[j].second] = r[j];
            }
            vector<set<int>> rank(1);
            for (int j = 0; j < 4; j++){
              rank[0].insert(j);
            }
            while (1){
              bool update = false;
              vector<set<int>> rank2;
              vector<int> points(4, 0);
              vector<int> gdiff(4, 0);
              vector<int> goals(4, 0);
              int cnt = rank.size();
              for (int j = 0; j < cnt; j++){
                int sz = rank[j].size();
                for (int k = 0; k < 4; k++){
                  for (int l = k + 1; l < 4; l++){
                    if (rank[j].count(k) && rank[j].count(l)){
                      if (result[k][l] > result[l][k]){
                        points[k] += 3;
                      } else if (result[k][l] < result[l][k]){
                        points[l] += 3;
                      } else {
                        points[k]++;
                        points[l]++;
                      }
                      gdiff[k] += result[k][l] - result[l][k];
                      gdiff[l] += result[l][k] - result[k][l];
                      goals[k] += result[k][l];
                      goals[l] += result[l][k];
                    }
                  }
                }
                map<tuple<int, int, int>, set<int>> mp;
                for (int k : rank[j]){
                  mp[make_tuple(points[k], gdiff[k], goals[k])].insert(k);
                }
                if (mp.size() > 1){
                  update = true;
                }
                for (auto itr = mp.rbegin(); itr != mp.rend(); itr++){
                  rank2.push_back((*itr).second);
                }
              }
              if (!update){
                break;
              } else {
                swap(rank, rank2);
              }
            }
            if (rank[0].count(team)){
              if (rank[0].size() <= 2){
                ans += tmp;
              } else {
                ans += tmp * 2 / rank[0].size();
              }
            } else if (rank[0].size() == 1 && rank[1].count(team)){
              ans += tmp / rank[1].size();
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3412