RPSSL  RockPaperScissorsLizardSpock
Daniel enjoys watching TV series. One of his favorite is "The Big Bang Theory". The main characters of this series are: Sheldon – genius theoretical physicist, his friend Leonard – talented experimental physicist, their attractive, blonde neighbor Penny, and also their friends an aerospace engineer Howard and a particle astrophysicist Rajesh.
One time Rajesh tells Sheldon:
“I'll tell you what. How about we go rockpaperscissors?”
“Ooh”, – Sheldon replies – “I don't think so. Anecdotal evidence suggests that in the game of rockpaperscissors, players familiar with each other will tie 75 to 80% of the time due to the limited number of outcomes. I suggest rockpaperscissorslizardSpock”.
“What?”
“It's very simple. Scissors cuts paper. Paper covers rock. Rock crushes lizard. Lizard poisons Spock. Spock smashes scissors. Scissors decapitates lizard. Lizard eats paper. Paper disproves Spock. Spock vaporizes rock. And as it always has, rock crushes scissors”.
“Okay, I think I got it”.
And the friends decided to play rockpaperscissorslizardSpock. And we would determine what the probability that Rajesh beats Sheldon in this game. We know the probabilities that any of the friends choose any object in the game. Also we know that they play till two wins, so the winner of the game is the person who first wins two rounds.
Input
The first line of input contains the number t  the number of tests. Next comes the description of t tests. Each test case consists of two lines. The first line contains five integers R_{R}, R_{Sc}, R_{P}, R_{L}, R_{Sp} – the probabilities that Rajesh chooses rock, scissors, paper, lizard or Spock respectively. The second line contains five integers S_{R}, S_{Sc}, S_{P}, S_{L}, S_{Sp} – the probabilities that Sheldon chooses rock, scissors, paper, lizard or Spock respectively. (Note: the order of the objects in the input is rock, scissors, paper, lizard, Spock. The original problem is in Russian and we have scissors before paper in Russian variant of the game. Otherwise the rules are the same.)
Constraints
1 <= t <= 500
0 <= R_{R}, R_{Sc}, R_{P}, R_{L}, R_{Sp} <= 100, R_{R} + R_{Sc} + R_{P} + R_{L} + R_{Sp} = 100
0 <= S_{R}, S_{Sc}, S_{P}, S_{L}, S_{Sp} <= 100, S_{R} + S_{Sc} + S_{P} + S_{L} + S_{Sp} = 100
Output
For each test case print the probability that Rajesh beats Sheldon in percent rounded to the nearest integer.
Example
Input: 2 10 20 30 40 0 10 10 10 10 60 20 20 20 20 20 20 20 20 20 20 Output: 66 50
hide comments
Abhishek Maurya:
20100730 23:51:23
No offense, I perceive that perhaps, based on the probabilities, given as an input in the quoted example, the Rajesh's winning probability as the output should be 55 and 40. Tell me if I'm wrong. 

:D:
20100326 13:22:15
Yes. If a tie (for a whole round) is possible then it's also certain and thus Rajesh can't win. 

Siarhei Khamenka:
20100326 12:32:04
so each game consists of 2 or 3 nontie rounds ? Last edit: 20100326 12:33:09 

Carlos Eduardo Rodrigues Alves [USJT]:
20100326 04:35:29
Well, here is a case where the game never ends:


Spooky:
20100324 18:20:24
yes it should be 67... 

Yandry Perez:
20100324 14:00:50
If P1=66.65..., shouldn't 67 be the answer? 

Spooky:
20100322 20:34:04
well you should calculate the probability that Rajesh wins... what is this probability if the game never ends?.. =P 

Jorge Bernadas:
20100322 17:55:10
What should we print if the game never ends? 
Added by:  Spooky 
Date:  20100317 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS OBJC PERL6 SQLITE VB.NET 
Resource:  Advancement Spring 2010, http://sevolymp.uuuq.com/ 