#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct S {
  int id, point, diff, goal;
  S(int id = -1): id(id), point(0), diff(0), goal(0) {}
  bool operator<(const S &s) {
    if (point != s.point) return point > s.point;
    if (diff != s.diff) return diff > s.diff;
    if (goal != s.goal) return goal > s.goal;
    return id < s.id;
  }
  bool operator==(const S &s) {
    return point == s.point && diff == s.diff && goal == s.goal;
  }
};

const int NUM = 8;
int N;
int pos;
int score[4][4];
vector<pii> ps;
double fac[9] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320};

void disp(string s, vector<int> v) {
  cout << s << " : ";
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " \n"[i+1==v.size()];
  }
}

void disp(string s, vector<vector<int>> v) {
  cout << s << " : ";
  for (int i = 0; i < v.size(); i++) {
    disp("  i = 0 ::", v[i]);
  }
  cout << endl;
}

void init() {
  pos = -1;
  fill_n((int*)score, 4*4, -1);
  ps.clear();
}

void input() {
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    cin >> s;
    if (s[0] == '*') pos = i;
    for (int j = i+1; j < 4; j++) {
      char lth = s[4 + 5*j + 2];
      char rth = s[4 + 5*j + 4];
      if (lth != '_') score[i][j] = lth - '0';
      else ps.emplace_back(i, j);
      if (rth != '_') score[j][i] = rth - '0';
      else ps.emplace_back(j, i);
    }
  }
}

double comb(int n, int k) {
  return fac[n] / fac[k] / fac[n-k];
}

double prob(int k) {
  return comb(NUM, k) * pow(1.0 / 4.0, k) * pow(3.0 / 4.0, NUM - k);
}

vector<vector<int>> makeGroup(vector<int> v) {
  vector<S> ss(v.size());
  for (int i = 0; i < v.size(); i++) ss[i].id = v[i];
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i == j) continue;
      int a = score[ss[i].id][ss[j].id], b = score[ss[j].id][ss[i].id];
      if (a > b) ss[i].point += 3;
      else if (a == b) ss[i].point += 1;
      ss[i].diff += a - b;
      ss[i].goal += a;
    }
  }
  sort(ss.begin(), ss.end());
  vector<vector<int>> res(1, vector<int>(1, ss[0].id));
  for (int i = 1; i < ss.size(); i++) {
    if (ss[i] == ss[i-1]) {
      res.back().emplace_back(ss[i].id);
    } else {
      res.emplace_back(vector<int>(1, ss[i].id));
    }
  }
  return res;
}

bool contain(vector<int> v, int x) {
  for (int vv : v) if (vv == x) return true;
  return false;
}

double calc(int a, int b, int c, int d) {
  vector<int> v{ps[0].first, ps[1].first, ps[2].first, ps[3].first};
  vector<vector<int>> vv(1, v), nvv, tmp;
  for (int i = 0; i < 3; i++) {
    nvv.clear();
    for (vector<int> x : vv) {
      tmp = makeGroup(x);
      for (vector<int> y : tmp) {
        nvv.emplace_back(y);
      }
    }
    swap(vv, nvv);
  }

  double res = prob(a) * prob(b) * prob(c) * prob(d);
  if (vv.size() > 0 && contain(vv[0], pos)) {
    if (vv[0].size() == 1) res *= 1.0;
    else res *= (vv[0].size() - 1) / comb(vv[0].size(), 2);
  } else if (vv.size() > 1 && vv[0].size() == 1 && contain(vv[1], pos)) {
    res *= 1.0 / vv[1].size();
  } else {
    res *= 0.0;
  }

  return res;
}

void solve() {
  double ans = 0;
  for (int i = 0; i <= NUM; i++) {
    for (int j = 0; j <= NUM; j++) {
      for (int k = 0; k <= NUM; k++) {
        for (int l = 0; l <= NUM; l++) {
          score[ps[0].first][ps[0].second] = i;
          score[ps[1].first][ps[1].second] = j;
          score[ps[2].first][ps[2].second] = k;
          score[ps[3].first][ps[3].second] = l;
          ans += calc(i, j, k, l);
        }
      }
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(7);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    init();
    input();
    solve();
  }

  return 0;
}


Measured memory_bytes: 3368