#K7216. Arranging Paintings Perfectly

    ID: 33692 Type: Default 1000ms 256MiB

Arranging Paintings Perfectly

Arranging Paintings Perfectly

You are given a wall with a specific height \(H\) and a maximum allowed total width \(W\). In addition, you have a list of paintings, each defined by its width and height.

Your task is to determine whether it is possible to arrange all the paintings on the wall such that:

  • No painting exceeds the wall height \(H\).
  • The sum of the widths of all paintings does not exceed \(W\).

The data for each test case is provided on a single line consisting of several space-separated integers. The first integer represents the height \(H\), the second the maximum total width \(W\), and the remaining integers represent the widths and heights of the paintings in pairs.

inputFormat

The first line contains an integer \(T\), which is the number of test cases. Each of the following \(T\) lines represents a test case in the format below:

\(H\, W\, p_{1w}\, p_{1h}\, p_{2w}\, p_{2h}\, \ldots, p_{nw}\, p_{nh}\)

  • \(1 \leq H \leq 100\)
  • \(1 \leq W \leq 10^5\)
  • For each painting \(i\): \(1 \leq p_{iw} \leq 1000\) and \(1 \leq p_{ih} \leq 1000\)

outputFormat

For each test case, output a single line containing Possible if the paintings can be arranged as required. Otherwise, output Impossible.

## sample
4
70 2000 100 50 300 70 150 60
80 1500 600 70 300 80 400 90
90 1000 500 100 600 80
100 2500 500 90 900 70 800 100
Possible

Impossible Impossible Possible

</p>