#Lutece3304. FIFA World Cup
FIFA World Cup
Description
The Qatar World Cup has begun! Many countries from all over the world are participating in this tournament.
We know that before the start of each match many bettors bet on the team they like or think will win. Suppose that two teams are bet on in a match in the ratio . Then if the first team wins, all bettors bet on it get times the profit, and if the second wins, all bettors bet on it get times the profit.
Mr. He is a veteran fan. Before the match starts, he scores all the teams. A total of games will be played. What a surprise, the ratio of the amount of money bet on each game is exactly equal to the ratio of his scores on the two teams. Now, Vingying also wants to bet on one of the teams (this has a negligible effect on the ratio of bets) and he wants to know the maximum amount of money he can get.
Note: To simplify the question, the possibility of a tie is not considered in this question.
Input
The first line contains an integer (), denoting the number of teams.
Each of the next lines contains a string and an integer (), denoting the name of the -th team and its score. The string contains only English letters, and the length won't exceed . Any two different teams won't have the same name.
The next line contains an integer (), denoting the number of matches.
Each of the next lines contains two strings and , denoting that the -th match is between the team and the team . It is guaranteed that and both of them appear in the set of .
Output
For each match, print a real number in one line, denoting the maximum amount of money that Vingying can get.
Your answer will be considered correct if and only if the absolute or relative error between yours and the jury is not bigger than .
Samples
4
Japan 1
Germany 100
SaudiArabia 10
Argentina 150
4
Japan Germany
SaudiArabia Argentina
Germany Argentina
SaudiArabia Japan
100.0
15.0
1.5
10.0
Resources
电子科技大学第十三届 ACM 趣味程序设计竞赛