LED Circuit
You are in charge of preparing the conference hall for the closing ceremony of ACM ICPC. You had hired a perfectionist sentimental room designer to design an elegant decoration for the old hall. The ceremony is going to start in a few hours and the designer has just informed you of the completion of the decoration. When you reach the conference hall, you confront a strange circuit on the wall. The designer starts explaining the meanings of life and ACM ICPC hidden under each piece of the circuit. The circuit consists of LEDs (Light Emitting Diodes) interconnected with junctions and wires. You ask whether the LEDs should be switched on. "Of course!" the designer responds, "Each and every LED must be lit, otherwise the whole work is junk!" You look around the circuit to find its power plug.
- Where is the power plug?
- Huh? It’s beyond the scope of my work! It is you who has to provide the electricity to the LEDs. And be careful! Do not remove or modify a single part of the circuit; Just connect power supply cables to the junctions. I have to leave right now. I will send a report of my perfect work to your manager. Bye.
Left alone with the bizarre circuit, you start inspecting the circuit.
Unlike incandescent light bulbs, which emit light regardless of the electrical polarity, LEDs only emit light with the correct electrical polarity (i.e. when their anode pin has a higher electric potential than the cathode pin). Each LED has a minimum voltage. An LED does not emit (even with the correct polarity) if the electrical potential difference of its pins is less than its minimum voltage. Each LED has also a maximum voltage. An LED is destroyed if its electrical potential difference exceeds its maximum voltage.
Your inspection on the circuit shows it consists of three types of components:
LEDs: Fortunately, all LEDs of the circuit are of the same type, and so having the same minimum voltage, and the same maximum voltage.
Junctions: Each of the two pins of an LED in the circuit is connected to a junction. Junctions are not only a place for connecting the LED pins, but also for connecting the wire end-points.
Wires: Each wire has two end-points and connects a junction directly to another junction forcing them to have the same electric potential.
By connecting external electrical poles (with different values of voltage) to each of the junctions of the circuit, you can inject different electric potentials to the junctions. Note that each junction must be connected to an external electrical pole. Be careful of short circuits: the end-points of each wire MUST have the same electric potential. By convention, we can assume the minimum electric potential to be zero. So, all the electric potentials can be considered to be nonnegative.
Now, you have to buy an external power supply that provides you with the required electrical poles. The cost of such power supplies depends on their upper-bound: the maximum voltage they provide.
Given the specification of the LED circuit, you have to write a program that tests if it is possible to light all the LED scorrectly (with no short circuits, and no LED destruction). In the case of the possibility, the program should also compute the minimum possible upper-bound of power supply with which all LEDs can emit light.
Input
The input consists of several test cases. Each test case describes an LED circuit and starts with a line containing 5 space-separated integers J, L, W, m, and M, where J is the number of junctions (2 ≤ J ≤ 500), L is the number of LEDs (1 ≤ L ≤ 5000), W is the number of wires (0 ≤ W ≤ 5000), and m and M are the minimum and maximum voltage of LEDs respectively (1 ≤ m < M ≤ 1000). Assume that the junctions are numbered 1 through J.
Each of the next L lines represents an LED with two space-separated integers. The first integer is the number of the junction to which the anode pin of the LED is connected and the second integer is the number of the junction for the cathode pin. Then, W lines follow, each describing a wire of the circuit using two space-separated integers: the junctions the wire directly connects.
The input terminates with a line containing "0 0 0 0 0" (omit the quotes).
Output
Write a single line of output for each test case. If there is no way to correctly light all the LEDs in the circuit of that test case, only write the word "Impossible" (with no quotes). Otherwise, write a single integer: the minimum upper-bound of power supply with which all the LEDs can be lit.