Problem: Following FIFA World Cup, a larger competition called ``GIGA Universe Cup'' is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as ``group league,'' and the second called ``final tournament.'' In the first round, participating teams are divided into groups of four teams each. Each team in a group plays a match against each of the other teams in the same group. For example, let's say we have a group of the following four teams, ``Engband, Swedon, Argontina, and Nigerua.'' They play the following six matches: Engband - Swedon, Engband - Argontina, Engband - Nigerua, Swedon - Argontina, Swedon - Nigerua, and Argontina - Nigerua.

The result of a single match is shown by the number of goals scored by each team, like ``Engband 1 - 0 Argontina,'' which says Engband scored one goal whereas Argontina zero. Based on the result of a match, points are given to the two teams as follows and used to rank teams. If a team wins a match (i.e., scores more goals than the other), three points are given to it and zero to the other. If a match draws (i.e., the two teams score the same number of goals), one point is given to each.

The goal difference of a team in given matches is the total number of goals it scored minus the total number of goals its opponents scored in these matches. For example, if we have three matches ``Swedon 1 - 2 Engband,'' ``Swedon 3 - 4 Nigerua,'' and ``Swedon 5 - 6 Argontina,'' then the goal difference of Swedon in these three matches is (1 + 3 + 5) - (2 + 4+ 6) = -3.

Given the results of all the six matches in a group, teams are ranked by the following criteria, listed in the order of priority (that is, we first apply (a) to determine the ranking, with ties broken by (b), with ties broken by (c), and so on).

(a) greater number of points in all the group matches;

(b) greater goal difference in all the group matches;

(c) greater number of goals scored in all the group matches.

If two or more teams are equal on the basis of the above three criteria, their place shall be determined by the following criteria, applied in this order:

(d) greater number of points obtained in the group matches between the teams concerned;

(e) greater goal difference resulting from the group matches between the teams concerned;

(f) greater number of goals scored in the group matches between the teams concerned;

If two or more teams are stiIl equal, apply (d), (e), and (f) as necessary to each such group. Repeat this until those three rules to equal teams do not make any further resolution. Finally, teams that still remain equal are ordered by:

(g) drawing lots by the Organizing Committee for the GIGA Universe Cup.

The two teams coming first and second in each group qualify for the second round.

Your job is to write a program which, given the results of matches played so far in a group and one team specified in the group, calculates the probability that the specified team will qualify for the second round. You may assume each team has played exactly two matches and has one match to play. In total, four matches have been played and two matches are to be played.

Assume the probability that any team scores (exactly) p goals in any match is:

<image>

for p ≤ 8, and zero for p > 8 . Assume the lot in the step (g) is fair.



Input

The first line of the input is an integer, less than 1000, that indicates the number of subsequent records.

The rest of the input is the indicated number of records. A single record has the following format:

<image>

In the above, <_> is a single underscore (_) and <empty> a sequence of exactly four underscores (____). Each of <team>1, ... , <team>4 is either an asterisk character (*) followed by exactly three uppercase letters (e.g., *ENG), or an underscore followed by exactly three uppercase letters (e.g., _SWE). The former indicates that it is the team you are asked to calculate the probability of the second round qualification for. You may assume exactly one of <team>1, ... , <team>4 is marked with an asterisk. Each <m>ij(1 ≤ i < j ≤ 4) is a match result between the <team>i and <team>j. Each match result is either __-_ (i.e., two underscores, hyphen, and another underscore) or of the form _x-y where each of x and y is a single digit (≤ 8) . The former indicates that the corresponding match has not been played, whereas the latter that the result of the match was x goals by <team>i and y goals by <team>j. Since each team has played exactly two matches, exactly two match results are in the former format.

Output

The output should consist of n lines where n is the number of records in the input. The ith line should show the probability that the designated team (marked with an asterisk) will qualify for the second round in the ith record.

Numbers should be printed with exactly seven digits after the decimal point. Each number should not contain an error greater than 10-7.

Example

Input

5
_____*AAA__BBB__CCC__DDD
*AAA_______0-0__0-0___-_
_BBB_____________-___0-0
_CCC_________________0-0
_DDD____________________
______CHN__CRC__TUR_*BRA
_CHN_______0-2___-___0-4
_CRC____________1-1___-_
_TUR_________________1-2
*BRA____________________
______CMR_*KSA__GER__IRL
_CMR_______1-0___-___1-1
*KSA____________0-8___-_
_GER_________________1-1
_IRL____________________
______TUN__JPN_*BEL__RUS
_TUN________-___1-1__0-2
_JPN____________2-2__1-0
*BEL__________________-_
_RUS____________________
______MEX__CRO_*ECU__ITA
_MEX_______1-0__2-1___-_
_CRO_____________-___2-1
*ECU_________________0-2
_ITA____________________


Output

0.5000000
1.0000000
0.0000000
0.3852746
0.0353304

Solution (in JAVA):

Solution:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//GIGA Universe Cup
public class Main{

	class R implements Comparable<R>{
		int id, nobattle, point, goal, diff;
		boolean concerned;
		int[] get, lose;
		public R(int id) {
			this.id = id;
			get = new int[4];
			lose = new int[4];
		}
		void calc1(){
			point = goal = diff = 0;
			for(int i=0;i<4;i++){
				if(id==i)continue;
				point += get[i]>lose[i]?3:get[i]==lose[i]?1:0;
				goal += get[i];
				diff += get[i]-lose[i];
			}
		}
		void calc2(){
			if(!concerned)return;
			point = goal = diff = 0;
			for(int i=0;i<4;i++){
				if(id==i||!teams[i].concerned)continue;
				point += get[i]>lose[i]?3:get[i]==lose[i]?1:0;
				goal += get[i];
				diff += get[i]-lose[i];
			}
		}
		public int compareTo(R o) {
			return point!=o.point?o.point-point:diff!=o.diff?o.diff-diff:o.goal-goal;
		}
		@Override
		public String toString() {
			String res = "";
			for(int i=0;i<4;i++){
				if(i==id)continue;
				res += " battle with: "+i+" ["+get[i]+"-"+lose[i]+"]";
			}
			return res;
		}
	}

	boolean exist(int f, List<R> list){
		for(R r:list)if(r.id==f)return true;
		return false;
	}

	List<R> ranking(List<R> list){
		List<R> res = new ArrayList<R>();
		for(int i=0;i<4;i++)teams[i].concerned = false;
		R[] t = new R[list.size()];
		for(int i=0;i<list.size();i++){
			t[i] = list.get(i);
			t[i].concerned = true;
		}
		for(int i=0;i<list.size();i++)t[i].calc2();
		Arrays.sort(t);
		res.add(t[0]);
		for(int i=1;i<list.size();i++)if(t[0].compareTo(t[i])==0)res.add(t[i]);
		return res;
	}

	R[] teams;
	double win(int f, List<R> list){
		double res = 0;
		int N = list.size();
		R[] tmp = new R[N];
		for(int i=0;i<N;i++)tmp[i]=list.get(i);
		for(int i=0;i<N;i++)tmp[i].calc1();
		Arrays.sort(tmp);
		List<R> first = new ArrayList<R>();
		first.add(tmp[0]);
		for(int i=1;i<N;i++)if(tmp[0].compareTo(tmp[i])==0)first.add(tmp[i]);
		if(first.size()==2){
			res = exist(f, first)?1:0;
//			System.out.println("RES: 1 " + res);

		}
		else if(first.size()>=2){
			if(!exist(f, first)){
				return 0;
			}
			List<R> t = new ArrayList<R>();
			for(R r:first)t.add(r);
			for(;;){
				int pre = t.size();
				t = ranking(t);
				if(t.size()==2){
					res = exist(f, t)?1:0;
					break;
				}
				if(t.size()==1){
					if(exist(f, t))return 1;
					int p = t.get(0).id;
					t = new ArrayList<R>();
					for(R r:first)if(p!=r.id)t.add(r);
					t = ranking(t);
					for(;;){
						int size = t.size();
						t = ranking(t);
						if(t.size()==1){
							return res = exist(f, t)?1:0;
//							System.out.println("RES: 3 " + res);
//							break;
						}
						if(size==t.size()){
							return res = exist(f, t)?(1.0/size):0;
//							break;
						}
					}
				}
				else if(pre==t.size()){
					return exist(f, t)?(2.0/pre):0;
				}
			}
//			int n = t.size();
//			if(n==2){
//				res = e?1:0;
//			}
//			else if(n==1){
//				res = e?1:(1.0/(n-1));
//			}
//			else{
//				res = e?2.0/n:0;
//			}
//			System.out.println("RES: 2 " + res);

		}
		else{
			if(exist(f, first))return 1;
			List<R> t = new ArrayList<R>();
			t.add(tmp[1]);
			for(int i=2;i<N;i++)if(tmp[1].compareTo(tmp[i])==0)t.add(tmp[i]);
			for(;;){
				int size = t.size();
				t = ranking(t);
				if(t.size()==1){
					res = exist(f, t)?1:0;
//					System.out.println("RES: 3 " + res);
					break;
				}
				if(size==t.size()){
					res = exist(f, t)?(1.0/size):0;
					break;
				}
			}
		}
		return res;
	}

	void run(){
		int[] fact = new int[9];
		fact[0]=1; for(int i=1;i<=8;i++)fact[i]=fact[i-1]*i;
		double[] gain = new double[9];
		for(int i=0;i<=8;i++)gain[i]=fact[8]/fact[i]/fact[8-i]*Math.pow(0.25, i)*Math.pow(0.75, 8-i);
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			String[] table = new String[5];
			teams = new R[4];
			for(int i=0;i<4;i++)teams[i]=new R(i);
			for(int i=0;i<5;i++)table[i]=sc.next();
			int focus = 0;
			for(int i=1;i<5;i++)if(table[i].startsWith("*"))focus = i-1;
			for(int i=0;i<4;i++)for(int j=i+1;j<4;j++){
				String sub = table[i+1].substring(6+5*j, 9+5*j);
				String[] s = sub.split("-");
				if(s[0].equals("_")){
					teams[i].nobattle = j;
					teams[j].nobattle = i;
				}
				else{
					int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
					teams[i].get[j] = x; teams[i].lose[j] = y;
					teams[j].get[i] = y; teams[j].lose[i] = x;
				}
			}
			List<R> l = new ArrayList<R>();
			for(int i=0;i<4;i++)l.add(teams[i]);
			double res = 0;
			for(int a=0;a<9;a++)for(int b=0;b<9;b++)for(int c=0;c<9;c++)for(int d=0;d<9;d++){
				double p = gain[a]*gain[b]*gain[c]*gain[d];
				int[] e = new int[]{a,b,c,d};
				for(int i=0;i<4;i++){
					teams[i].get[teams[i].nobattle] = e[i];
					teams[i].lose[teams[i].nobattle] = e[teams[i].nobattle];
				}
				res += p*win(focus, l);
			}
			System.out.printf("%.7f\n", res);
		}
	}

	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}