#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 TT (1T10001\leq T\leq 1000) in the first line indicates the number of cases.

Then followed by TT cases.

The first line of each case contains 22 integers AA BB(1A,B1091\leq A, B\leq 10^9). The size of the room is A×BA\times B (AA for the horizontal edge and BB for the vertical edge).

Next 44 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 n a1 b1an bnn\ a_1\ b_1\cdots a_n\ b_n. (0n500\leq n\leq 50,for upper and lower side: 0ai<biA0\leq a_i < b_i\leq A, biai+1b_i\leq a_{i+1}; for left and right side: 0ai<biB0\leq a_i < b_i\leq B, biai+1b_i\leq a_{i+1}). Interval [ai,bi][a_i, b_i] 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