Problem E : Jackpot

inputfile: E.IN

outputfile: E.OUT

Description

An addicted gambler walks from his home to the casino every day to try his luck. He likes most games but the one he likes most is the slot machine, also known as the jackpot or the one-armed-bandit. Because of his years of experience he exactly knows which, and how many, symbols appear on the wheels of every slot machine. Unfortunately all wheels have changed since last time he was in the casino. The wheels are completely new, vary in size and are much larger than the former ones. He wonders if there's a way to find out which slot machine would give him the most profit. He suspects that a lot of calculations are involved so he decides that this job can better be done by a computer.

Problem

Can you build a program for this man which calculates the pay-rate of a number of machines, if the complete wheels are known? There are three wheels on each machine, all three wheels rotate independently of each other. Each line of three times the same symbol pays an amount of money. The display of the machine consists of three visible rows. The middle row pays 10 coins if three identical symbols are shown, both the upper and the lower row pay 5 coins. In addition, the line from the upper left corner to the lower right as well as the line from the lower left to the upper right corner can result in a winning combination. They both pay 7 coins. The pay-rate is defined as the average (or expected) amount of money paid by the machine on each play.

Input

The first line gives the number of slot machines s . Then for each slot machine follows:

Output

The output consists of s lines with on each line the pay-rate of the corresponding slot machine, with exact 4 digits after the decimal point. Note: a variance of ñ 0.0001 is allowed in the output due to rounding differences.

Example

Sample input

2
3 4 6
AAB
BABA
BBAAAB
12 15 18
CCCCCCCCCCCC
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCC

Correct output for the sample input

8.5000
34.0000