people are playing football (soccer), divided into two teams. Each player wears a dress with the team logo and a unique (in the team) positive integer between and , inclusive. For each player, we know his precision, the set of teammates whom he can pass the ball to and the set of opponents who can take the ball from him . When a player comes into possession of the ball, after exactly one second one of the following events will happen:
- the player passes the ball to a random teammate from the set ,
- a random opponent from the set takes the ball from him,
- the player attempts a shot at the goal
If the player attempts a shot, the probability of scoring a goal is equal to his precision. After the shot, whether it was successful or not, the ball is awarded to the player number from the opposing team.
The probabilities of different events are in the proportion , in order, and depend only on the player currently in possession of the ball ( determines the size of the set corresponding to the current player), not on any previous events in the game. The word "random" means that all players from the set (or ) have the same probability of being passed (or taking) the ball by (from) the player that is currently in the ball's possession. The time that a ball spends outside of a player's possession is negligible.
The match begins with player from the first team in possession of the ball and ends either when one team has scored goals or when seconds have elapsed, whichever happens first. For each possible final score, determine the probability that the match will end with it.
The following image illustrates the player arrangement for the second test example:
Input Specification
The first line of input contains three positive integers: , the number of players in each team, , the number of goals needed for victory, and , the maximum duration of the match.
The following lines contain descriptions of the first team's players, one per line, while the next lines after that contain descriptions of the second team's players. A description of a single player consists of a real number , the player's precision, followed by two positive integers, and , the sizes of the sets and , respectively, followed by player labels representing the sets and themselves (in that order), all space-separated. Note that the labels from represent players from one team, and labels from the other team. The set will not contain the label of the player currently being described.
Output Specification
The match can theoretically end with one of different final results. For each result, output the probability of its realization as a real number, one per line. Order the results first by the number of goals scored by the first team, then by the number of goals scored by the second team, in ascending order. The permitted difference from the exact value for each probability is .
Sample Input 1
1 1 2
0.5 0 1 1
0.5 0 1 1
Sample Output 1
0.56250
0.18750
0.25000
Explanation for Sample Output 1
The star denotes the player in possession of the ball in the beginning. The match lasts for only moves or until someone scores goal. Since , there are only two players in the match, playing one against the other. Both players have the precision of , which means that each has a chance of scoring a goal when trying to shoot, after which the ball is awarded to the opponent.
Let us label the grey player as , and the white player as . Under these assumptions, there are only possible matches. Each of them is described in the table below, with the corresponding probability, description and outcome:
decides to shoot and scores! | ||
decides to shoot, but misses. decides to shoot and scores! | ||
decides to shoot, but misses. decides to shoot, but also misses! | ||
loses the ball to . decides to shoot and scores! | ||
loses the ball to . loses the ball to . | ||
loses the ball to . decides to shoot, but misses. |
By summing probabilities for particular final results, we obtain the following solution:
Comments