F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Everyone Has His Wing Broken

Time 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
3 3 7 5 9 3 1 2 7 1 3 5 2 3 9 1 1 2 3 1 1 20 1 1 2 2 2 1 2 1 3 3 1 1 20 1 1 2 3 2 1 2 1 3
 

Sample Output
Case 1: -5 Case 2: 0 0 Case 3: Impossible!
 

Hint

The gambles do not have to happen in the given order.
 

Author
Sakuya
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-03 04:13:43, Gzip enabled