#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
  
vector<ld>pers(9);

void getper() {
	for (int i = 0; i <= 8; ++i) {

		ld per = 1;
		for (int j = 1; j <= 8; ++j) {
			per *= j;
		}
		for (int j = 1; j <= i; ++j) {
			per /= j;
		}
		for (int j = 1; j <= 8 - i; ++j) {
			per /= j;
		}
		for (int j = 1; j <= 8; ++j) {
			per /= 4;
		}
		for (int j = 1; j <= 8 - i; ++j) {
			per *= 3;
		}
		pers[i] = per;
	}
}

struct game {
	int a;
	int b;
	int ap;
	int bp;
};

struct score {
	int id;
	int win;
	int goal_dif;
	int goal_num;
	long long int rate;
	score(const int id_, const int win_, const int goal_dif_, const int goal_num_) {
		id = id_;
		win = win_;
		goal_dif = goal_dif_;
		goal_num = goal_num_;
		calc();
	}
	void calc() {

		rate = win * 10000 + goal_dif * 100 + goal_num;
	}
	score() {
		id = 0;
		win = 0;
		goal_dif = 0;
		goal_num = 0;
		calc();
	}
	void update(const int goal, const int op_goal) {
		if (goal > op_goal)win += 3;
		else if (goal == op_goal)win += 1;
		goal_dif += goal - op_goal;
		goal_num += goal;
		calc();
	}
};


vector<score>getscores(const vector<vector<game>>&games, const vector<int>&points, const set<int>aset=set<int>{ 0,1,2,3 }) {
	int now = 0;
	vector<score>scores(4);
	for (int a = 0; a < 3; ++a) {
		for (int b = 1 + a; b < 4; ++b) {
			int ap, bp;
			if (games[a][b - 1 - a].ap == -1) {
				ap = points[now];
				now++;
				bp = points[now];
				now++;
			}
			else {
				ap = games[a][b - 1 - a].ap;
				bp = games[a][b - 1 - a].bp;
			}
			if (aset.find(a) != aset.end() && aset.find(b) != aset.end()) {
				scores[a].update(ap, bp);
				scores[b].update(bp, ap);
			}
		}
	}
	for (int j = 0; j < 4; ++j) {
		scores[j].calc();
	}
	return scores;
}

int main() {
	int N; cin >> N;
	getper();
	while (N--) {
		int winner;
		vector<vector<game>>games(4);
		for (int i = 0; i < 5; ++i) {
			string st; cin >> st;
			if (i == 0) {
				for (int j = 0; j < 4; ++j) {
					if (st[5 * j + 5] == '*')winner = j;
				}
			}
			else {
				for (int j = i+1; j <= 4; ++j) {
					char a = st[5 * j + 1];
					char b = st[5 * j + 3];
					if (a == '_') {
						games[i-1].push_back(game{ i - 1,j - 1,-1,-1});
					}
					else {
						games[i - 1].push_back(game{ i - 1,j - 1,a - '0',b - '0' });
					}
				}
			}
		}

		ld ans = 0;
		for (int i = 0; i < 9 * 9 * 9 * 9; ++i) {
			ld per = 1;
			vector<int>points(4);
			int n(i);
			for (int j = 0; j < 4; ++j) {
				points[j] = n%9;
				n /= 9;
				per *= pers[points[j]];
			}


			set<int>aset;
			int flag = 1;
			int passnum;
			{
				vector<score>scores=getscores(games,points);
				map<int, set<int>>idmp;
				for (int j = 0; j < 4; ++j) {
					idmp[-scores[j].rate].emplace(j);
				}

				int pass = 0;
				for (auto m : idmp) {
					int nextpass = pass + m.second.size();
					if (m.second.find(winner) != m.second.end()) {
						if (nextpass <= 2) {
							flag = 1;
						}
						else if (pass >= 2) {
							flag = -1;
						}
						else {
							flag = 0;
							passnum = 2 - pass;
							aset=(m.second);
						}
					}
					pass = nextpass;
				}
			}
			if (flag == 0) {
				set<int>aaset;
				int aaflag = 1;
				int aapassnum;
				{
					vector<score>scores = getscores(games, points,aset);
					
					map<int, set<int>>idmp;
					for (int j = 0; j < 4; ++j) {
						if (aset.find(j) != aset.end()) {

							idmp[-scores[j].rate].emplace(j);
						}
					}

					int pass = 0;
					for (auto m : idmp) {
						int nextpass = pass + m.second.size();
						if (m.second.find(winner) != m.second.end()) {
							if (nextpass <= passnum) {
								aaflag = 1;
							}
							else if (pass >= passnum) {
								aaflag = -1;
							}
							else {
								aaflag = 0;
								aapassnum = passnum -pass;
								aaset=(m.second);
							}
						}
						pass = nextpass;
					}
				}
				if (aaflag == 1) {
					ans += per;
				}
				else if (aaflag == 0) {
					set<int>aaaaset;
					int aaaaflag = 1;
					int aaaapassnum;
					{
						vector<score>scores = getscores(games, points, aaset);

						map<int, set<int>>idmp;
						for (int j = 0; j < 4; ++j) {
							if (aaset.find(j) != aaset.end()) {

								idmp[-scores[j].rate].emplace(j);
							}
						}

						int pass = 0;
						for (auto m : idmp) {
							int nextpass = pass + m.second.size();
							if (m.second.find(winner) != m.second.end()) {
								if (nextpass <= aapassnum) {
									aaaaflag = 1;
								}
								else if (pass >= aapassnum) {
									aaaaflag = -1;
								}
								else {
									aaaaflag = 0;
									aaaapassnum = aapassnum - pass;
									aaaaset = (m.second);
								}
							}
							pass = nextpass;
						}
					}
					if (aaaaflag == 1) {
						ans += per;
					}
					else if (aaaaflag == 0) {
						ans += per / aaaaset.size()*aaaapassnum;
					}
				}
			}
			else {
				if (flag == 1) {
					ans += per;
				}
			}
			
			
		}
		printf("%.7f\n", double(ans));
	}
	return 0;
}

Measured memory_bytes: 3256