#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct result {
	int x, y, cx, cy;
};
result a[6];
int target;
int c[4];
void a_calc() {
	rep(i, 4) {
		c[i] = 0;
	}
	rep(i, 6) {
		if (a[i].cx > a[i].cy)c[a[i].x] += 3;
		else if (a[i].cx < a[i].cy)c[a[i].y] += 3;
		else {
			c[a[i].x]++; c[a[i].y]++;
		}
	}
}
void b_calc() {
	rep(i, 4) {
		c[i] = 0;
	}
	rep(i, 6) {
		c[a[i].x] += a[i].cx - a[i].cy;
		c[a[i].y] += a[i].cy - a[i].cx;
	}
}
void c_calc() {
	rep(i, 4) {
		c[i] = 0;
	}
	rep(i, 6) {
		c[a[i].x] += a[i].cx;
		c[a[i].y] += a[i].cy;
	}
}
void d_calc(vector<int> v) {
	rep(i, 4) {
		c[i] = 0;
	}
	int exi[4] = {};
	rep(i, v.size()) {
		exi[v[i]] = 1;
	}
	rep(i, 6) {
		if (!exi[a[i].x] || !exi[a[i].y])continue;
		if (a[i].cx > a[i].cy)c[a[i].x] += 3;
		else if (a[i].cx < a[i].cy)c[a[i].y] += 3;
		else {
			c[a[i].x]++; c[a[i].y]++;
		}
	}
}
void e_calc(vector<int> v) {
	rep(i, 4) {
		c[i] = 0;
	}
	int exi[4] = {};
	rep(i, v.size()) {
		exi[v[i]] = 1;
	}
	rep(i, 6) {
		if (!exi[a[i].x] || !exi[a[i].y])continue;
		c[a[i].x] += a[i].cx - a[i].cy;
		c[a[i].y] += a[i].cy - a[i].cx;
	}
}
void f_calc(vector<int> v) {
	rep(i, 4) {
		c[i] = 0;
	}
	int exi[4] = {};
	rep(i, v.size()) {
		exi[v[i]] = 1;
	}
	rep(i, 6) {
		if (!exi[a[i].x] || !exi[a[i].y])continue;
		c[a[i].x] += a[i].cx;
		c[a[i].y] += a[i].cy;
	}
}
vector<int> a_rule(vector<int> u) {
	vector<int> res;
	a_calc();
	vector<P> v;
	rep(i, u.size()) {
		v.push_back({ c[u[i]],u[i] });
	}
	sort(v.begin(), v.end(),greater<P>());
	int cnt = 0;
	rep(i, v.size()) {
		res.push_back(v[i].second);
		while (i + 1 < v.size() && v[i].first == v[i + 1].first) {
			i++; res.push_back(v[i].second);
		}
		cnt++;
		if (cnt == 1)break;
	}
	sort(res.begin(), res.end()); return res;
}
vector<int> b_rule(vector<int> v) {
	vector<int> res;
	b_calc();
	vector<P> u;
	rep(i, v.size()) {
		u.push_back({ c[v[i]],v[i] });
	}
	sort(u.begin(), u.end(), greater<P>());
	int cnt = 0;
	rep(i, u.size()) {
		res.push_back(u[i].second);
		while (i + 1 < u.size() && u[i].first == u[i + 1].first) {
			i++; res.push_back(u[i].second);
		}
		cnt++; if (cnt == 1)break;
	}
	sort(res.begin(), res.end()); return res;
}
vector<int> c_rule(vector<int> v) {
	vector<int> res; c_calc();
	vector<P> u;
	rep(i, v.size()) {
		u.push_back({ c[v[i]],v[i] });
	}
	sort(u.begin(), u.end(), greater<P>());
	int cnt = 0;
	rep(i, u.size()) {
		res.push_back(u[i].second);
		while (i + 1 < u.size() && u[i].first == u[i + 1].first) {
			i++; res.push_back(u[i].second);
		}
		cnt++; if (cnt == 1)break;
	}
	sort(res.begin(), res.end()); return res;
}
vector<int> d_rule(vector<int> v) {
	vector<int> res; d_calc(v);
	vector<P> u;
	rep(i, v.size()) {
		u.push_back({ c[v[i]],v[i] });
	}
	sort(u.begin(), u.end(), greater<P>());
	int cnt = 0;
	rep(i, u.size()) {
		res.push_back(u[i].second);
		while (i + 1 < u.size() && u[i].first == u[i + 1].first) {
			i++; res.push_back(u[i].second);
		}
		cnt++; if (cnt == 1)break;
	}
	sort(res.begin(), res.end()); return res;
}
vector<int> e_rule(vector<int> v) {
	vector<int> res; e_calc(v);
	vector<P> u;
	rep(i, v.size()) {
		u.push_back({ c[v[i]],v[i] });
	}
	sort(u.begin(), u.end(), greater<P>());
	int cnt = 0;
	rep(i, u.size()) {
		res.push_back(u[i].second);
		while (i + 1 < u.size() && u[i].first == u[i + 1].first) {
			i++; res.push_back(u[i].second);
		}
		cnt++; if (cnt == 1)break;
	}
	sort(res.begin(), res.end()); return res;
}
vector<int> f_rule(vector<int> v) {
	vector<int> res; f_calc(v);
	vector<P> u;
	rep(i, v.size()) {
		u.push_back({ c[v[i]],v[i] });
	}
	sort(u.begin(), u.end(), greater<P>());
	int cnt = 0;
	rep(i, u.size()) {
		res.push_back(u[i].second);
		while (i + 1 < u.size() && u[i].first == u[i + 1].first) {
			i++; res.push_back(u[i].second);
		}
		cnt++; if (cnt == 1)break;
	}
	sort(res.begin(), res.end()); return res;
}
ld ret() {
	bool one = false;
	vector<int> v = { 0,1,2,3 }; vector<int> cop;
	cop = v; v = a_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
		v = a_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}
	cop = v; v = b_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
		v = b_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}
	cop = v; v = c_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
		v = c_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}
	cop = v;
		v = d_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = d_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = e_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == i)continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = e_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = f_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v =f_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = d_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = d_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = e_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == i)continue;
			cv.push_back(cop[i]);
		}
		v = cv;
		v = e_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = f_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = f_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = d_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = d_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = e_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == i)continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = e_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}cop = v;
		v = f_rule(v);
	if (v.size() == 1 && !one) {
		one = true;
		if (v[0] == target)return 1;
		vector<int> cv;
		rep(i, cop.size()) {
			if (v[0] == cop[i])continue;
			cv.push_back(cop[i]);
		}
		v = cv;
			v = f_rule(v);
	}
	if (v.size() == 1) {
		if (v[0] == target)return 1;
		else return 0;
	}
	if (!one) {
		rep(i, v.size()) {
			if (v[i] == target) {
				return 2 / (ld)v.size();
			}
		}
		return 0;
	}
	else {
		rep(i, v.size()) {
			if (v[i] == target) {
				return 1 / (ld)v.size();
			}
		}
		return 0;
	}
}
ld pos[9];
ld pp[9];
void init() {
	pp[0] = 1;
	rep1(i, 8) {
		pp[i] = pp[i - 1] * i;
	}
	rep(i, 9) {
		pos[i] = pp[8] / (pp[i] * pp[8 - i]);
		rep(j, i) {
			pos[i] *= 0.25;
		}
		rep(j, 8 - i) {
			pos[i] *= 0.75;
		}
		//cout << pos[i] << endl;
	}
}
P check[6] = { {1,11},{1,16},{1,21},{2,16},{2,21},{3,21} };
P loc[6] = { {0,1},{0,2},{0,3},{1,2},{1,3},{2,3} };
int main() {
	init();
	cout << fixed << setprecision(8);
	int n; cin >> n;
	rep(aa, n) {
		string s[5];
		rep(i, 5) {
			cin >> s[i];
			if (s[i][0] == '*')target = i-1;
		}
		ld out = 0;
		//int num = 0, hie = 0;
		rep(p1, 9) {
			rep(p2, 9) {
				rep(p3, 9) {
					rep(p4, 9) {
						int now = 0; int cnow = 0;
						rep(i, 6) {
							int x = check[i].first; int y = check[i].second;
							if (s[x][y] == '_') {
								if (cnow == 0) {
									a[i] = { loc[i].first,loc[i].second,p1,p2 }; cnow++;
								}
								else {
									a[i] = { loc[i].first,loc[i].second,p3,p4 };
								}
							}
							else {
								a[i] = { loc[i].first,loc[i].second,s[x][y] - '0',s[x][y + 2] - '0' };
							}
						}
						out += pos[p1] * pos[p2] * pos[p3] * pos[p4] * ret();
						//if (ret() == 1)num++;
						//if (ret() == 0)hie++;
					}
				}
			}
		}
		cout << out << endl;
		//cout << num << " " << hie << endl;
	}
	return 0;
}


Measured memory_bytes: 3280