#include<bits/stdc++.h>
using namespace std;

int point[4][4][2];
int target;
int holl[2][2];

double prob[9];

pair<int, int> getScore(int i, int j){
	if(i < j){
		return pair<int, int>(point[i][j][0], point[i][j][1]);
	}else{
		return pair<int, int>(point[j][i][1], point[j][i][0]);
	}
}

vector<pair<int, int> > check(vector<int> vec){
	bool flg[4] = {false, false, false, false};
	vector<pair<array<int, 3>, int> > scores; 
	for(int i = 0; i < vec.size(); i++){
		flg[vec[i]] = true;	
		scores.push_back({{0, 0, 0}, vec[i]});
	}

	for(auto& p : scores){
		for(int i = 0; i < 4; i++){
			if(p.second == i || !flg[i]) continue;

			pair<int, int> s = getScore(p.second, i);
			if(s.first > s.second){
				p.first[0] += 3;
			}else if(s.first == s.second){
				p.first[0] += 1;
			}
			p.first[1] += s.first - s.second;
			p.first[2] += s.first;
		}
	}
	sort(scores.begin(), scores.end(), greater<pair<array<int, 3>, int> >());
	vector<pair<int, int> > answer;
	for(int i = 0; i < scores.size(); i++){
		vector<int> next;
		next.push_back(scores[i].second);
		while(i+1 < scores.size() && scores[i].first == scores[i + 1].first){
			next.push_back(scores[i + 1].second);
			i++;
		}
		if(next.size() == 1){
			answer.push_back(pair<int, int>(next[0], 1));
		}else if(next.size() == vec.size()){
			for(auto p : next){
				answer.push_back(pair<int, int>(p, next.size()));
			}
		}else{
			for(auto p : check(next)){
				answer.push_back(p);
			}
		}
	}
	return answer;
}


double check(int target){
	/*
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i >= j) cout << "    ";
			else cout << " " << point[i][j][0] << "-" << point[i][j][1];
		}
		cout << endl;
	}
	*/
	vector<int> vec;
	for(int i = 0; i < 4; i++){
		vec.push_back(i);
	}
	vector<pair<int, int> > res = check(vec);
	int rank = 0;
	int cur = 0;
	for(int i = 0; i < 4; i++){
		if(rank <= i) {
			rank += res[i].second;
			cur = i;
		}
		//printf("%d %d %d\n", cur, res[i].first, res[i].second);
		if(res[i].first == target){
			if(res[i].second == 1){
				if(i < 2) return 1.0;
				else return 0;
			}else{
				if(cur == 0) return 2.0 / res[i].second;
				else if(cur == 1) return 1.0 / res[i].second;
				else return 0;
			}
		}
	}
}

int fact(int v){
	if(v == 0) return 1;
	else return v * fact(v - 1);
}

int main(){
	for(int i = 0; i <= 8; i++){
		prob[i] = fact(8) * pow(1.0/4.0, i) * pow(3.0/4.0, 8 - i) / fact(i) / fact(8 - i); 
	}

	int N;
	int target;

	cin >> N;
	string str;
	getline(cin, str);
	while(N--){
		getline(cin, str);
		int pi = 0;
		for(int i = 0; i < 4; i++){
			getline(cin, str);
			if(str[0] == '*') target = i;
			for(int j = i + 1; j < 4; j++){
				if(str[6 + j * 5] == '_'){
					holl[pi][0] = i;					
					holl[pi][1] = j;					
					pi++;
				}else{
					point[i][j][0] = str[6 + j * 5] - '0';
					point[i][j][1] = str[8 + j * 5] - '0';
				}
			}
		}

		double ans = 0;
		for(int i = 0; i <= 8; i++){
			for(int j = 0; j <= 8; j++){
				for(int k = 0; k <= 8; k++){
					for(int l = 0; l <= 8; l++){
						point[ holl[0][0] ][ holl[0][1] ][ 0 ] = i;
						point[ holl[0][0] ][ holl[0][1] ][ 1 ] = j;

						point[ holl[1][0] ][ holl[1][1] ][ 0 ] = k;
						point[ holl[1][0] ][ holl[1][1] ][ 1 ] = l;
						double val = check(target);
						ans += prob[i] * prob[j] * prob[k] * prob[l] * val;
					//	cout << val << endl;
					//	return 0;
					}
				}
			}
		}
		printf("%.10f\n", ans);
	}
}

Measured memory_bytes: 3364