#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 x:yx:y. Then if the first team wins, all bettors bet on it get yx\frac{y}{x} times the profit, and if the second wins, all bettors bet on it get xy\frac{x}{y} times the profit.

Mr. He is a veteran fan. Before the match starts, he scores all the nn teams. A total of mm 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 11 on one of the teams (this 11 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 nn (2n1002\le n \le 100), denoting the number of teams.

Each of the next nn lines contains a string NameiName_i and an integer ScoreiScore_i (1Scorei2001\le Score_i \le 200), denoting the name of the ii-th team and its score. The string contains only English letters, and the length won't exceed 2020. Any two different teams won't have the same name.

The next line contains an integer mm (1m1001\le m \le 100), denoting the number of matches.

Each of the next mm lines contains two strings AiA_i and BiB_i, denoting that the ii-th match is between the team AiA_i and the team BiB_i. It is guaranteed that AiBiA_i \ne B_i and both of them appear in the set of NameiName_i.

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 10610^{-6}.

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 趣味程序设计竞赛