Balloon Recovery

Distribute a shared energy budget across height changes so every balloon riding layered winds reaches position zero as early as possible.

Hard8Binary searchDynamic programmingNo attempts yetTime limit5sMemory limit512 MB

Problem

Company G has released many balloons into the sky. To service a balloon, the company has to collect it at its tower, which stands at horizontal position 00. Balloon ii is at horizontal position PiP_i and height HiH_i.

The engineers raise and lower a balloon by radio, telling it to drop ballast or let out air. They cannot move a balloon horizontally, so it depends on the wind at its height.

A balloon can sit at MM heights, numbered 00 to M1M-1. The wind at height jj has velocity VjV_j. A positive VjV_j means the wind blows from left to right, and a negative VjV_j means it blows from right to left. A balloon at position PP that stays at a height with wind velocity VV is at position P+tVP + tV after time tt. Time runs continuously, so tt can be any real number. The moment a balloon's position becomes 00, it is collected.

Moving one balloon from height aa to height bb costs ab|a - b| energy. A height change takes no time, and you may change a balloon's height at any moment and as many times as you want. You have QQ energy for all balloons together, and you do not have to spend all of it.

Find the time it takes to collect every balloon when you spend the energy optimally. Time is counted in whole units: the answer is the smallest integer that is greater than or equal to the earliest moment by which every balloon is collected. If the last balloon is collected at time 1.51.5, the answer is 22.

Input

The first line contains the number of test cases TT.

The first line of each test case contains the number of balloons NN, the number of heights MM, and the available energy QQ, separated by spaces. The second line contains MM integers, where the jjth value (counting from 00) is the wind velocity VjV_j at height jj. Each of the next NN lines contains the position PiP_i and the height HiH_i of balloon ii.

Limits

  • 1T251 \le T \le 25
  • 1N1001 \le N \le 100
  • 1M10001 \le M \le 1000
  • 100Vj100-100 \le V_j \le 100
  • 1Q100001 \le Q \le 10000
  • 0Hi<M0 \le H_i < M
  • 10000Pi10000-10000 \le P_i \le 10000

Output

For each test case, print one line in the form "Case #x: y". Here xx is the test case number starting from 11, and yy is the minimum time needed to collect every balloon. If the given energy is not enough to collect every balloon, print IMPOSSIBLE in place of yy.

Note

In the first test case of the first example there are two balloons and 11 energy point. The best move is to spend that point lowering the balloon at position 33, height 33 to height 22. The wind at height 22 has velocity 2-2, so that balloon reaches the tower at time 1.51.5. The balloon at position 2-2, height 11 rides a wind of velocity 11 and reaches the tower at time 22. Both balloons are collected by time 22, so the answer is 22.