|
||||||||||
Everyone Has His Wing BrokenTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 283 Accepted Submission(s): 42 Special Judge Problem Description Long long ago, N gamblers (numbered from 1 to N) got together to gamble. At that time, the kinds of gamble were not that much diversified. The gamble can only be performed in a way that two people played against each other and the one who lost the game would have to give the winner $1. Furthermore, the one who lose all his money and lose for another time would get out and never come back. But he still has to pay $1 (He may sell his pants). After playing for quite a long time, they felt as if they had their wings broken, for everyone still here won nothing. As one of the gamblers, mzry1992 wondered what really happened. Now mzry1992 wants you to tell him what happened between some pairs, for example how much does gambler A win from gambler B directly. But actually you do not know the real situation. So you could just tell him one of the possible situations. Input There are T cases and the first line of the input contains the number T. The first line of each case consists of one integer N(2 ¡ÜN¡Ü500), indicating the number of gamblers. Then comes N lines. The i-th line is a non-negative integer smaller than 101 indicating the i-th gambler's initial possess. The next line contains one integer M(0¡ÜM¡Ü10000), indicating the number of pairs of gamblers who gambled. The following M line contains three integer A, B, t(1¡ÜA, B¡ÜN, 1¡Üt¡Ü100), which means that the gamble A and the gamble B played the game for t times. The final part of each test case begins with an integer Q (1¡ÜQ¡Ü200000). Then Q lines follows. Each line contains two integers A, B. You are asked to answer how much gambler A wins from B. Output Output the all the queries from mzry1992.For each test case, your answer should assume that all of the gambles could happen in the one situation. If there is no such situation, just output ¡°Impossible!. Sample Input
Sample Output
Hint The gambles do not have to happen in the given order. Author Sakuya Source | ||||||||||
|