#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int myteam;
pii board[4][4];
double fact[10], prob[10];
double ans;

vector<int> order(int S){
    vector<int> point(4, 0), diff(4, 0), score(4, 0);
    vector<int> id;
    rep(i, 4)if(S>>i & 1) id.push_back(i);
    rep(x, 4)if(S>>x & 1){
        For(y, x+1, 4)if(S>>y & 1){
            int s, t;
            tie(s, t) = board[x][y];
            score[x] += s; score[y] += t;
            diff[x] += s - t; diff[y] += t - s;

            if(s > t) point[x] += 3;
            else if(s < t) point[y] += 3;
            else point[x] += 1, point[y] += 1;
        }
    }
    auto cmp = [&](const int &i, const int &j){
        if(point[i] != point[j]) return point[i] > point[j];
        if(diff[i] != diff[j]) return diff[i] > diff[j];
        return score[i] > score[j];
    };
    sort(id.begin(), id.end(), cmp);

    vector<int> pri(4, -1);
    int cur = 0;
    for(int l=0; l<(int)id.size();){
        int r = l;
        int T = 0;
        while(r < (int)id.size() && !cmp(id[l], id[r])){
            T |= (1 << id[r]);
            ++r;
        }
        if(r - l == 1 || S == T){
            For(i, l, r) pri[id[i]] = cur;
            ++cur;
        }
        else{
            auto p = order(T);
            int ncur = cur + 1;
            For(i, l, r) pri[id[i]] = cur + p[id[i]], chmax(ncur, pri[id[i]] + 1);
            cur = ncur;
        }
        l = r;
    }

    return pri;
}

void dfs(int cur, double p){
    if(cur == 2){
        auto pri = order((1<<4)-1);
        int mypos, cnt[4];
        rep(i, 4) cnt[i] = 0;
        rep(i, 4){
            if(i == myteam) mypos = pri[i];
            ++cnt[pri[i]];
        }

        if(mypos == 0) p *= min(1.0, 2.0 / (double)cnt[0]);
        else if(mypos == 1 && (int)cnt[0] < 2){
            p *= 1.0 / (double)cnt[1];
        }
        else p = 0;

        ans += p;
        return;
    }

    rep(x, 4)For(y, x+1, 4)if(board[x][y].fi < 0){
        rep(s, 9)rep(t, 9){
            board[x][y] = {s, t};
            dfs(cur + 1, p * prob[s] * prob[t]);
        }
        board[x][y] = {-1, -1};
        return;
    }
}

void solve(){
    char gomi, name[5];
    rep(i, 4) scanf(" %c", &gomi);
    rep(i, 4){
        rep(j, 5) scanf(" %c", &name[j]);
        if(name[1] == '*') myteam = i;
    }

    rep(i, 4)rep(j, 4) board[i][j] = {-1, -1};
    rep(i, 4){
        char gomi, result[5];
        rep(k, 4) scanf(" %c", &gomi);
        rep(j, 4){
            rep(k, 5) scanf(" %c", &result[k]);
            if(isdigit(result[2])){
                board[i][j] = {result[2] - '0', result[4] - '0'};
            }
        }
    }

    ans = 0;
    dfs(0, 1.0);
    printf("%.10lf\n", ans);
}

int main(){
    fact[0] = 1;
    For(i, 1, 10) fact[i] = fact[i-1] * i;
    rep(p, 9){
        prob[p] = 40320 / fact[p] / fact[8-p] * pow(0.25, p) * pow(0.75, 8-p);
    }
    int t;
    scanf("%d", &t);
    rep(tt, t){
        solve();
    }
}


Measured memory_bytes: 3412