gBalloon (Small)

Spend at most Q height-change energy across balloons with layered winds to minimize the time when the last balloon reaches position 0.

Medium6Dynamic programmingBinary searchNo attempts yetTime limit5sMemory limit512 MB

Problem

Company G keeps many balloons in the air. To service them, the balloons have to be brought back to the company tower, which stands at horizontal position 0. Balloon ii is now at horizontal position PiP_i and height HiH_i.

The engineers at G can only change the height of a balloon, by sending a radio signal that drops ballast or lets air out. They cannot push a balloon sideways, so horizontal motion is left to the wind.

A balloon can be at one of MM heights, numbered 0 to M1M-1. The wind differs from height to height. At height jj the wind has velocity VjV_j: a positive value blows from left to right, a negative value from right to left. A balloon that stays at height jj and starts at position PP is at P+VjP + V_j after one time unit and at P+2VjP + 2V_j after two time units. The balloon drifts at a constant speed inside a time unit as well, and the moment its position becomes 0 it touches the tower and is collected right away. A balloon that passes 0 in the middle of a time unit is collected at that moment.

Changing a height takes no time but costs energy. Moving one balloon from height HoldH_{\text{old}} to height HnewH_{\text{new}} costs HoldHnew|H_{\text{old}} - H_{\text{new}}| energy. Heights may be changed only at integer times, that is at time 0 and at the end of each time unit, and there is no limit on the number of changes. All balloons draw from one budget of QQ energy, and you do not have to spend all of it.

Spend the energy in the best possible way and find how long it takes to collect every balloon.

Input

The first line holds the number of test cases TT. The first line of each test case holds the number of balloons NN, the number of heights MM, and the available energy QQ.

The second line holds MM integers. The jjth value on this line, counting from 0, is the wind velocity VjV_j at height jj.

Each of the next NN lines holds the horizontal position PiP_i and the height HiH_i of one balloon.

Limits

  • 1T1001 \le T \le 100
  • 1N101 \le N \le 10
  • 1M101 \le M \le 10
  • 10Vj10-10 \le V_j \le 10
  • 1Q101 \le Q \le 10
  • 0Hi<M0 \le H_i < M
  • 10Pi10-10 \le P_i \le 10

Output

For each test case, print one line in the form Case #x: y. xx is the test case number, starting from 1, and yy is the smallest integer such that every balloon is collected no later than time yy. If the given energy is not enough to collect every balloon, print IMPOSSIBLE in place of yy.

Note

The first sample case has two balloons and 1 unit of energy. The best plan is to spend that unit at the start and drop the balloon at position 3, height 3 down to height 2. The wind at height 2 has velocity 2-2, so this balloon drifts from position 3 to 1 and then from 1 to 1-1, passing position 0 in the middle of the second time unit. The balloon at position 2-2, height 1 rides a wind of velocity 1 and reaches position 0 at time unit 2. Collecting both balloons therefore takes 2 time units.