#Lutece0104. Sensor
Sensor
Migrated from Lutece 104 Sensor
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
An exhibition of an invaluable jewel is around the corner. The jewel is now placed in a rectangular room, and some infrared sensor is necessary for security reason. The infrared sensor can be set on the wall and detect unusual movement in the area perpendicular to the sensor, but only some part of the wall is available. To avoid blind spots, sensors must be installed appropriately. Your task is to calculate the minimum number of sensors needed to install (measure in the length they cover the wall).
Input
One integer () in the first line indicates the number of cases.
Then followed by cases.
The first line of each case contains integers (). The size of the room is ( for the horizontal edge and for the vertical edge).
Next lines describes the available part for sensors respectively on the upper ,lower,left and right side of the room, which is in the format of . (,for upper and lower side: , ; for left and right side: , ). Interval specifies those parts. You can see pictures above for more details.
Output
For each case, print the minimum number of required sensors on a line if it's possible to complete the task, or print Impossible
otherwise.
Samples
3
3 4
0
0
0
0
9 6
1 0 3
1 3 9
2 2 4 5 6
3 0 1 3 4 4 5
9 6
0
0
2 2 4 5 6
3 0 1 3 4 4 5
Impossible
9
Impossible
Resources
The 8th UESTC Programming Contest Preliminary