#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


//#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
string names[4];
int target = 0;
vector<pair<pair<int, int>, pair<int, int>>> results;
long double calc() {
    vector<int> going{ 0,1,2,3 };
    vector<int> winner;
    REP(t, 3) {
        map<tuple<int, int, int>, vector<int>> next;
        tuple<int, int, int> cnter[4] = {};
        REP(i, going.size()) {
            REP(q, going.size()) {
                REP(j, results.size()) {
                    if (results[j].first == mp((int)going[i], (int)going[q])) {
                        if (results[j].second.first == results[j].second.second) {
                            get<0>(cnter[going[i]])--;
                            get<0>(cnter[going[q]])--;
                        }
                        else if (results[j].second.first > results[j].second.second) {
                            get<0>(cnter[going[i]]) -= 3;
                        }
                        else {
                            get<0>(cnter[going[q]]) -= 3;
                        }
                        get<1>(cnter[going[i]]) -= results[j].second.first - results[j].second.second;
                        get<1>(cnter[going[q]]) -= results[j].second.second - results[j].second.first;
                        get<2>(cnter[going[i]]) -= results[j].second.first;
                        get<2>(cnter[going[q]]) -= results[j].second.second;
                    }
                }
            }
        }
        REP(i, going.size()) {
            next[cnter[going[i]]].push_back(going[i]);
        }
        if ((*next.begin()).second.size() + winner.size() >= 2) {
            going = (*next.begin()).second;
        }
        else {
            vector<int> hoge = (*next.begin()).second;
            REP(j, hoge.size()) {
                winner.push_back(hoge[j]);
            }
            auto x = next.begin();
            x++;
            if (x != next.end()) {
                going = (*x).second;
            }
            else {
                going.clear();
                break;
            }
        }
    }
    REP(i, winner.size()) {
        if (winner[i] == target) {
            return 1.0L;
        }
    }
    long double now = 2 - (int)winner.size();
    REP(i, going.size()) {
        if (target == going[i]) {
            return now / (long double)(going.size());
        }
    }
    return 0;
}
long double memo[9];
long double scoring(int a) {
    if (memo[a]) return memo[a];
    long double ans = 1;
    for (int i = 2; i <= 8; ++i) {
        ans *= (long double)i;
    }
    for (int i = 2; i <= a; ++i) {
        ans /= (long double)i;
    }
    for (int i = 2; i <= 8 - a; ++i) {
        ans /= (long double)i;
    }
    REP(i, a) {
        ans /= (long double)4;
    }
    REP(i, 8 - a) {
        ans /= (long double)4;
        ans *= (long double)3;
    }
    return memo[a] = ans;
}
void solve() {
    results.clear();
    vector<string> inputs;
    string a;
    cin >> a;
    REP(i, 4) {
        string a;
        cin >> a;
        inputs.push_back(a);
    }
    REP(i, 4) {
        if (inputs[i][0] == '*') {
            target = i;
        }
        names[i] = inputs[i].substr(1, 3);
    }
    vector<pair<int, int>> no;
    REP(i, 4) {
        for (int q = i+1; q < 4; ++q) {
            string b = inputs[i].substr(6 + q * 5, 3);
            if (b[0] == '_') {
                no.push_back(mp(i, q));
            }
            else {
                pair<pair<int, int>, pair<int, int>> now = mp(mp((int)i, (int)q), mp((int)(b[0] - '0'), (int)(b[2] - '0')));
                results.push_back(now);
            }
        }
    }
    results.push_back(mp(no[0], mp(-1, -1)));
    results.push_back(mp(no[1], mp(-1, -1)));
    long double ans = 0;
    REP(i, 9) {
        REP(q, 9) {
            REP(j, 9) {
                REP(t, 9) {
                    long double prob = scoring(i) * scoring(q) * scoring(j) * scoring(t);
                    results[results.size()-1].second = mp(i, q);
                    results[results.size()-2].second = mp(j, t);
                    ans += prob * calc();
                }
            }
        }
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    int t;
    cin >> t;
    REP(tea,t)
    solve();
}


Measured memory_bytes: 3296