Superstitious Helicopter Pilots

No attempts yetTime limit1sMemory limit128 MB

Problem

Helicopter pilots are conservative and superstitious. Every pilot has a list of preferred hops (10 km east and 20 km north, for instance), written down from the most preferred one to the least. There are also spots a pilot refuses to land on, such as the pig farm 20 km east and 50 km north of here.

Put the start at (0,0)(0, 0) and the destination at (E,N)(E, N), that is EE east and NN north. A flight plan is a sequence of preferred hops that ends exactly at (E,N)(E, N). Every point the pilot lands on, the destination included, must not be a forbidden point. The start does not count as a landing, so it is never checked.

The superstition adds one more rule. At every step the pilot takes the most preferred hop among those that still leave the rest of the journey possible.

Say the destination is 30 km east and 40 km north, the preferred hops are (10,10)(10, 10) and (0,10)(0, 10) in that order, and (30,30)(30, 30) is forbidden. One northerly hop followed by three north-easterly ones reaches the destination as (0,10) 3*(10,10), but the plan the rule picks is 2*(10,10) (0,10) (10,10): two north-easterly hops, then a northerly one, then a last north-easterly one. If (20,30)(20, 30) were forbidden as well, no flight plan would exist at all.

In every journey the distance east and the distance north are positive integers. A preferred hop has a non-negative distance east and a non-negative distance north, and the two are never both 0.

Input

The input holds several journeys. Each journey starts with a line of four integers EE, NN, HH, FF: the distance east, the distance north, the number of preferred hops, and the number of forbidden points. Then come the HH preferred hops, most preferred first, and after them the FF forbidden points. Both are written as an east distance and a north distance on one line. Some hops may go unused, and some forbidden points may lie beyond the destination. The input ends with a line of four zeros, 0 0 0 0.

Output

Print one line per journey. Each line starts with Trip , then the journey number counting up from 1, then a colon and a space, then the flight plan written as hops. A run of kk identical hops in a row is written as k*(east,north), and a hop that occurs once is written as (east,north). No space goes inside the parentheses, and one space separates neighbouring groups. If the journey cannot be flown, print impossible in place of the flight plan.